Salesforce Rest API create account

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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:

@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/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x