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?

1 Answer 1


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:

global with sharing class MyRestResource {

    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
    Commented Jan 24, 2019 at 17:53

You must log in to answer this question.

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