1

We are using the Salesforce Rest API to integrate our external website with Salesforce Sales Cloud. When a user registers on our website, we create a contact record in Salesforce. The response to the initial insert request includes the Contact ID. Is there a way we can have the initial request return more fields? On the SF side, we have a formula field that generates the 18 digits long contact ID and we need that returned to us for interacting with the Marketing Cloud. We can make another call to get this long contact ID but we are trying to avoid this extra call. Is what we are trying to do achievable?

3

yes, it is possible by means of creating custom rest resource in salesforce and inserting contact via this endpoint.


you want to add one more additional step before returning newly created contact. This step is to query this 18 digits long contact ID field. for example:

@RestResource(urlMapping='/ContactInsertWithReturnedFields/*')
global with sharing class MyRestResource {

    @HttpPost
    global static String doPost(String lastName) {
        Contact cont = new Contact(
            LastName = lastName
            );
        insert cont;
        cont = [
            select Id, LongContactId__c // query all needed fields to be returned on insert call
            from Contact
            where Id = :cont.Id
            limit 1
            ];
        return cont;
    }
}

in this case endpoint is https://instance.salesforce.com/services/apexrest/ContactInsertWithReturnedFields/

  • Thanks Oleksandr, I was able to solve this via the APEX Rest API as you suggested. Much appreciated. – degmo Jan 24 at 17:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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