1

Relatively new to working with the Salesforce API. Trying to create a new record for a custom object we have created in Salesforce. Below is the code I am using to create this custom object, I am making sure I am using the API names for the object itself as well as for the fields.

<?php

$username = "myusername";
$password = "mypassword";

define("SOAP_CLIENT_BASEDIR", "Force.com-Toolkit-for-PHP-master/soapclient");

require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');

try {

  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($username, $password);

  $sObject = new stdclass();
  $sObject->First_name__c = 'Test';
  $sObject->Last_name__c = 'Test';
  $sObject->Email__c = 'test@test.com';
  $sObject->RecordType = "MyCustomRecordType";
  $sObject->Name = "API Testing";

  $createResponse = $mySforceConnection->create(array($sObject), 'CustomObject__c');

} catch (Exception $e) {
  var_dump($e);
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}

?>

The error I am receiving from this code is the following:

No fields provided in an external foreign key reference in entity: RecordType

This is how the standard fields for the object looks like in Salesforce.

enter image description here

I made sure my RecordType name matches that of the record type configured in Salesforce.

What am I missing here? Thank you.

1

I've solved this by running the API call

describeSObject

against my custom object. Looking through the result, I noticed that the record type field's name was instead

RecordTypeId

There was also a list of all record types and their ID's in this API call, something I did not see when browsing my record type in the Salesforce UI.

So instead of

$sObject->RecordType = "MyCustomRecordType";

I am now using

$sObject->RecordTypeId = "XXXXXXXXXXXXXX";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.