You need to sign in to do that
Don't have an account?
Diwakar G 7
Post Request in Trigger
Hi,
I am trying to make a post request if a field value updates. Below is the code.
Above code is working fine for single record update. If it is batch update then only field value is getting updated and it is not making a post call. Please help me.
Thanks and Regards,
Diwakar G
I am trying to make a post request if a field value updates. Below is the code.
trigger StatusChange on User_Story__c (after update) { User_Story__c u = trigger.new[0]; User_Story__c updacc=[select id,name,userStory_reason__c from User_Story__c where id = :u.id]; if(Trigger.oldmap.get(updacc.id).userStory_reason__c != Trigger.newmap.get(updacc.id).userStory_reason__c ){ Getrequest.apicall(); } }Apex Class:
global class Getrequest { @Future(callout=true) public static void apicall(){ HttpRequest req = new HttpRequest(); String endpoint = 'https://xxxxxxxx.xxxxxxxxxxxxx.com/xxxx'; String temp ='A'; String temp1 = 'B'; String jsonData = '[{"name":"'+temp+'"},{"Request":"'+temp1+'"}]'; req.setBody(jsonData); req.setEndpoint(endpoint); req.setHeader('Accept', 'application/json'); req.setMethod('POST'); Http http = new Http(); http.send(req); } }
Above code is working fine for single record update. If it is batch update then only field value is getting updated and it is not making a post call. Please help me.
Thanks and Regards,
Diwakar G
Hi Diwakar ,
Try below code
Reference : https://developer.salesforce.com/forums/?id=9060G000000BdVjQAK