function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vibhor M 7Vibhor M 7 

Customize API response

I have created a connected app and through Postman I am inserting a Lead with an external id. In the response I get the salesforce Id instead I want to get the external id + salesforce id. How can I achieve this.

TIA
GovindarajGovindaraj
Hi Vibhor,

I hope, you con go with Apex REST service instead of using standard Api,
@RestResource(urlMapping='/insertLeads/*')
global class leadController {
@HttpPost
global static String createNewLead() { 
Lead objLead = new Lead(); 
insert objLead; 
return id + externalId; //Modify the response as per need
}
}
Thanks,
Govindaraj.S
Raj VakatiRaj Vakati
Try this code and your apex class rest api must be like this 
 
@RestResource(urlMapping='/insertLeads/*')
global class leadController {
@HttpPost
global static String createNewLead(String lName ,String fName ,String email ,String eId ) { 
Lead objLead = new Lead(); 
objLead.FirstName = fName ; 
objLead.LastName = lName ; 
objLead.Email = email ; 
objLead.External_Id__c = eId ; 
insert objLead; 
return objLead.Id + objLead.External_Id__c; //Modify the response as per need
}
}