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.


$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 = '[email protected]';
  $sObject->RecordType = "MyCustomRecordType";
  $sObject->Name = "API Testing";

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

} catch (Exception $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 Answer 1


I've solved this by running the API call


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


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";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .