0
votes

I have to create record from my webapp to salesforce :

error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
ini_set('xmlrpc_errors', true);

define("USERNAME", "xxxxxxxxx");
define("PASSWORD", "xxxxxxxxx");
define("SECURITY_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxx");

require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

function createRecord(){

    global $mySforceConnection;

    $records = array();

    $records[0] = new stdclass();
    $records[0]->FirstName = 'Myriam';
    $records[0]->LastName = 'Makeba';
    $records[0]->Phone = '(510) 555-5555';
    $records[0]->BirthDate = '1957-01-25';
    $records[0]->contractType__c = "CDI";

    $response = $mySforceConnection->create($records, 'Contact');

    $ids = array();
    foreach ($response as $i => $result) {
        echo $records[$i]->FirstName . " " . $records[$i]->LastName . " "
                . $records[$i]->Phone . " created with id " . $result->id
                . "<br/>\n";
        array_push($ids, $result->id);
    }
}

You see that i want to update custom field "contractType__c", it throws me an error :

Fatal error: Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'TypeContrat__c' on entity 'Contact'.
If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. 
Please reference your WSDL or the describe call for the appropriate names.

if i comment this line, it inserts the records, my aim is to update custom field of salesforce. Sorry for my bad english.

Thank you.

Oups! last news i tried to insert record without the custom field, i also got error :

stdClass Object ( 
[errors] => Array ( 
[0] => stdClass Object ( 
[message] => ContactBeforeInsert: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.ContactBeforeInsert: line 83, column 1 [statusCode] => CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ) ) 
[id] => [success] => ) 
stdClass Object ( 
[errors] => Array ( 
[0] => stdClass Object ( 
[message] => ContactBeforeInsert: execution of BeforeInsert caused by: System.NullPointerException: **Attempt to de-reference a null object Trigger.ContactBeforeInsert: line 83**, column 1 [statusCode] => CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ) ) [id] => [success] => )
1

1 Answers

0
votes

First Error:

As per your description you are getting issue " INVALID_FIELD: No such column 'TypeContrat__c' on entity 'Contact'. So please check api name of this field in salesforce. I think you are missing something in api name of custom field of contact.

Second Error:

In your salesforce org there is an trigger "ContactBeforeInsert" for contact and in that it's getting an null pointer exception. (Means they are retrieving some value and that is null). So please check that trigger. Follow the steps to see the list of contact trigger's goto setup-> Customize -> contact -> trigger.