You need to sign in to do that
Don't have an account?
Aaron Attard
JSON POST send details from created record to external endpoint
I have this apex trigger & apex class that trigger when a record is created. This works well when sending text as string in the request.setbody, however I need to replace the "name" & "external_id" with values from the created record within inverted commas.
The end result should be sending JSON text as follows:
{
"options": [ {"name": "Job Name A", "priority": 0, "external_id": "a1H0J000005xP6E"} ]
}
//Apex Trigger trigger [ApexTriggerName] on [ObjectRecord] (after insert) {AfterInsertCreateJob.jobs();}
//Apex Class public class AfterInsertCreateJob { @future(callout=true) public static void jobs(){ Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://example.com'); request.setMethod('POST'); request.setHeader('Content-Type','application/json'); request.setHeader('On-Behalf-Of','[userid]'); request.setHeader('Authorization','[password]'); request.setBody('{"options":[{"name":"record.name","priority":0,"external_id":"record.id"}]}'); System.debug('1: ' + request); HttpResponse response = http.send(request); System.debug('2: ' + response); } }
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi Mukesh
Thanks a lot, that worked!
I also needed to amend the request.setBody line as follows to ensure that id and name values are sent within "".
Regards
Aaron