Reputation: 1172
When using the Salesforce SOAP API via PHP, if I have an object which has a look-up field to an account with a specific field on the account which is set up as an external id, I can do the following
$sfBooking->fields['Account__r'] = "<type>Account</type>"
. "<custom_account_id__c>"
. utf8_encode($tboxBooking->client_id)
. "</custom_account_id__c>";
This is quite handy when trying to link records without have to resort to using their Salesforce ID.
I'm wondering is there a similar type of shorthand I can use when setting up the Record Type on objects via the API. Having to get the record type id by first querying the Record Type object is a step I'd like to cut out if at all possible.
Upvotes: 3
Views: 840
Reputation: 19050
You can do this using the name field on RecordType, your generated xml should look like
<create xmlns="urn:partner.soap.sforce.com">
<sobject>
<type>case</type>
<subject>Test</subject>
<recordType>
<type>RecordType</type>
<name>InternetCase</name>
</recordType>
</sobject>
</create>
based on the code you posted, you'd do
$sfBooking->fields['RecordType'] = "<type>RecordType</type>"
. "<name>"
. utf8_encode($tboxBooking->recordType_name)
. "</name>";
Upvotes: 1
Reputation: 239
David, I'm not aware of a similar shorthand method of setting the RecordType. Unfortunately the RecordType does not have an external id which is required in order to achieve this.
My recommendation would be to query all of the RecordTypes and build up a local lookup table/array of DeveloperName to Id. You can then use this lookup table/array throughout your application to set the correct RecordType Id based on the DeveloperName of that RecordType in Salesforce.
Upvotes: 1