1

I am looking for a way to pass key-value in salesforce rest API payload for inserting a record. By using below rest API.

/services/data/v47.0/sobjects/Account/

And access those key-value pairs in before triggers to calculate values for actual fields of the Account object.

My scenario 3rd party application inserts a record in salesforce using Salesforce REST API. The payload has the name of the group it belongs, but Account has lookup(Group), Id has to be assigned not name. So how do I find group Id in before triggers and assign to account before saving?

I don't want to write a custom REST API class.

Any suggestions appreciated.

  • 2
    In addition to David's excellent answer, have a look at Composite resources it might help you. – identigral Mar 12 at 17:45
  • 1
    Oh man, I forgot about composite resources. Great pointer. – David Reed Mar 12 at 18:24
2

You should consider leveraging Standard REST API via the Composite API. Your integration will need to changed, but you can still avoid custom REST.

Consider the following... two Standard REST API calls chained together:

{
"compositeRequest" : [
        {
            "method" : "GET",
            "url" : "/services/data/v47.0/query/?q=select id, name from <<sObject>> where name ='Alpha Beta' ",
            "referenceId" : "existingSObjectRecord"
        },
        {
            "method" : "POST",
            "url" : "/services/data/v47.0/sobjects/Account/",
            "referenceId" : "AccountId",
            "body" : {
                "Name" : "New Account To Insert",
                "Custom_Lookup_Field__c" : "@{existingSObjectRecord.id}"
            }
        }
    ]
}
| improve this answer | |
3

You can't do that. The standard REST API will not accept arbitrary parameters or pass them along to your custom code.

I don't want to write a custom REST API class.

You will need to do that or change your integration design.

My scenario 3rd party application inserts a record in salesforce using Salesforce REST API. The payload has the name of the group it belongs, but Account has lookup(Group), Id has to be assigned not name.

If the name can be made an External Id field, you could potentially use an upsert operation to automatically lookup and link this relationship. That would obviate the need for custom code. For details on this approach, please see the section Upserting Records and Associating with an External ID in this document. Your external system would have to call the upsert endpoint and submit a payload analogous to

{
   "Name" : "Record Name",
   "Group__r" :
   {
       "Group_Name__c" : "Test"
   }
}

Where the Group_Name__c field is an External Id.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.