xmlrestsalesforcelookup

Update records having relationship field using xml and REST API


I'm following the documentation on updating an object with a relationship field, but I'm getting an error. The documentation is using JSON files.

I want to update a record which is associated with an other object via a lookup relationship,

The account has a lookup relationship with the country__c object the country__c has an external Id: Code__c

My xml file is as below:

<records type="Account">
    <UsualName__c>TESTCNTR</UsualName__c>
    <Phone>+123456789</Phone>
    <MainCountry__r>
        <Country__c>
            <Code__c>TN</Code__c>
        </Country__c>
    </MainCountry__r>
</records>

I tried this format but I'm always getting the 400 error code

<records type="Account">
    <UsualName__c>usualTESTCNTR</UsualName__c>
    <Phone>+123456789</Phone>
    <MainCountry__c type="Country__c">
        <Code__c>TN</Code__c>
    </MainCountry__c>
</records>

The update is successful when I tried to update only simple field (phone and usual name).

Hopefully I'm just doing something wrong, does anyone have any ideas? Thanks


Solution

  • It works with this XML syntax :

    <records type="Account">
        <UsualName__c>TESTCNTR2</UsualName__c>
        <Phone>+123456789</Phone>
        <MainCountry__r>
            <Code__c>TN</Code__c>
        </MainCountry__r>
    </records>