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
lauraecilauraeci 

HTTP HttpRequest fails in Triggers Callout from triggers are currently not supported.

Apex script unhandled trigger exception by user/organization: 005U0000000IWs4/00DU0000000JDvW

 

AssociateSection: execution of BeforeUpdate

 

caused by: System.CalloutException: Callout from triggers are currently not supported.

 

Trigger.AssociateSection: line 58, column 1

 

Is there a work around for adding an HTTP post inside a trigger? Apex Classes??

 

Thanks!

Navatar_DbSupNavatar_DbSup

Hi,

 

HTTP HttpRequest Callouts does not work out in triggers. You can call them From Apex Classes.

 

Small Code how to use Http request in Apex Classes

 

 

        httprequest hreq=new httprequest();

        string refresh_url='https://login.salesforce.com/services/oauth2/token?grant_type=refresh_token&client_id='+consumer_key+'&client_secret='+client_secret+'&refresh_token='+refresh_token;

       

        hreq.Setendpoint(refresh_url);

      

        hreq.setHeader('Authorization:', 'OAuth '+acc_tken);

        hreq.setmethod('POST');

        hreq.setHeader('Content-Type', 'text/xml;charset=UTF-8');

        hreq.setHeader('Accept', 'application/xml;charset=UTF-8');

        hreq.setHeader('Host','ap1.salesforce.com');

        http htp=new http();

        httpResponse res=htp.send(hreq);

        readXMLResponseOfFutureAccessToken(res.getBody());

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

craigmhcraigmh

You have to make callouts after any DML operations.

 

Change the trigger to be "after update", perform all of your DML, then perform the callout(s).

Sam AlexSam Alex
If we cant send call out from triggers how to perform them after update?