0

How can i make an upsert callout? I have object Contact with custom ExtId with Custom_Object__c id. So i am tried post, patch method and without/with '?_HttpMethod=PATCH'; What do i need to do? I can only update or insert. HttpRequestHandler just do common part.

 Map<String, String> headers = new Map<String, String>();
            headers.put('Authorization', 'Bearer ' + credentials.Access_Token__c);
            headers.put('Content-Type', 'application/json');
            headers.put('accept', 'application/json');
`String endpoint = 'https://login.salesforce.com/services/data/v52.0/sobjects/contact/' + contact.ExtId__c + '?_HttpMethod=PATCH';`

HttpRequestHandler req = new HttpRequestHandler ('PATCH', body, endpoint, credentials, headers);

1 Answer 1

1

you need to specify the external id field in the endpoint, like these:

String endpoint = 'https://login.salesforce.com/services/data/v52.0/sobjects/contact/ExtId__c/' + contact.ExtId__c;

If you are doing the callout in Apex, you can check this example to set the HTTP method before and after Winter 21 releasement

How can I make a PATCH HTTP Callout from Apex?

Reference: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm

1
  • oh, thanks. Got it.
    – Femladamli
    Aug 23, 2021 at 16:36

You must log in to answer this question.

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