Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k 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 (32.1k points)
edited by

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

Learn about Salesforce by signing up for this professional Salesforce course online!

Browse Categories

...