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
Diwakar G 7Diwakar G 7 

Post Request in Trigger


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 =[0];
    User_Story__c updacc=[select id,name,userStory_reason__c from User_Story__c where id =];
    if(Trigger.oldmap.get(  != Trigger.newmap.get( ){


Apex Class:
global class Getrequest {

    public static void apicall(){
            HttpRequest req = new HttpRequest();
        	String endpoint = '';
        	String temp ='A';
        	String temp1 = 'B';
        	String jsonData = '[{"name":"'+temp+'"},{"Request":"'+temp1+'"}]';
            req.setHeader('Accept', 'application/json');
      		Http http = new Http();


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 :

global class BatchSync implements Database.Batchable<sObject>,   Database.AllowsCallouts {
     public String query = 'Select ID, Name from Account';
     global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(query);
         global void execute(Database.BatchableContext BC, List<Account> records) {         
             for ( integer i = 0; i< records.size(); i++ ){
                 // do your job
        global void finish(Database.BatchableContext BC){    
            String endpoint; 
            try {                  
                HttpRequest req = new HttpRequest();
                HttpResponse res = new HttpResponse();
                Http http = new Http();
                // Set values to Params
                endpoint = 'Your endpoint';
                req.setHeader('Authorization', header);
                req.setHeader('Content-Type', 'application/json');
                req.setBody('Information you wanna send');
                req.setCompressed(true); // This is imp according to SF, but please check if
                // the webservice accepts the info. Mine did not :P
                // Had to set it to false
                if (!Test.isRunningTest()) {      
                    res = http.send(req);
                    String sJson = res.getBody();
                    System.debug('Str:' + res.getBody());
                // now do what u want to with response.               
            catch (Exception e) {         
                System.debug('Error:' + e.getMessage() + 'LN:' + e.getLineNumber() );