4

I'm upserting a custom object via the REST api. How can I use the REST api to populate the record owner using an external id? See details below:

Endpoint:

/services/data/v42.0/sobjects/finserv__Alert__c/FinServ__SourceSystemId__c/test-external_id

Method: PATCH

Body:

{  
    "FinServ__Account__r":{  
        "External_Id__c":"account-external-id-1"
    },
    "FinServ__Message__c":"Alert-Subject-Finserv-CREATE-1",
    "FinServ__MessageDescription__c":"Alert-Description-Finserv-CREATE-1",
    "FinServ__Active__c":false,
    "Owner":{  
        "External_Id__c":"user-external-id-1"
    }
}

I get the following error when I run this in workbench:

message: Unexpected character ('F' (code 70)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]
errorCode: JSON_PARSER_ERROR

This seems to be because Owner is a UserOrGroup lookup, and not a lookup to a single object. The moment I remove "Owner": {...} from the payload, it succeeds.

How can I use the REST api to populate the record owner using an external id?

2
  • when you put in a valid SF user id into that field what happens? Also, can you post the request class that you are deserializing your json to? Commented May 14, 2019 at 23:18
  • 4
    You're going to have to write a custom endpoint if you want to support that behavior, or add a separate field to hold the external id, then populate OwnerId via trigger.
    – Adrian Larson
    Commented May 15, 2019 at 0:57

2 Answers 2

4

Even though this question is one year old I had the same issue today and found a solution to that problem.

With standard Rest API, your request only needs a slight modification:

{  
    "FinServ__Account__r":{  
        "External_Id__c":"account-external-id-1"
    },
    "FinServ__Message__c":"Alert-Subject-Finserv-CREATE-1",
    "FinServ__MessageDescription__c":"Alert-Description-Finserv-CREATE-1",
    "FinServ__Active__c":false,
    "Owner": {
        "attributes": {
            "type": "User"  
        },
        "External_Id__c":"user-external-id-1"
    }
}

Note the additional hint to what will actually be transferred within Owner structure via the attributes sub type.

I did not find official documentation on this, however, it just works. :)

-1

I used a Custom REST API and populated OwnerId via the apex logic of the Custom REST API

You must log in to answer this question.

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