0 votes
1 view
in Salesforce by (11k points)

When using the Salesforce SOAP API via PHP, if I have an object which has a lookup 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 having 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.

1 Answer

0 votes
by (27.8k points)

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