+ Start a Discussion
yuvrajindiayuvrajindia 

CalloutException when Post HTTPRequest

 

        String  strXML ='<?xml version="1.0" encoding="utf-8"?><clickAPI><sendMsg><api_id>3253451</api_id><user>Medlert</user><password>Password</password><to>919826471817</to><text>SMS Message</text></sendMsg></clickAPI>';
        String strUrl = 'http://api.clickatell.com/xml/xml';

       
       HttpRequest req = new HttpRequest();

       
        req.setBody(strXML);
        req.setMethod('POST');
        req.setEndpoint(strUrl);
        req.setHeader('Content-Type', 'text/xml');
        req.setHeader('X-If-No-Redirect', '1' );
        
        Http http = new Http();
        HTTPResponse res = http.send(req);

 I am useing this code but this is throw exeption:

 

System.CalloutException: Callout from triggers are currently not supported

 

Also use this code from globel class with webservice but then how can i call that class.

 

What is currect way to run this code.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
dkadordkador

As the exception says - we don't support making HTTP callouts in triggers.  You could put this callout in an Apex future request and invoke that future request from the callout.

All Answers

dkadordkador

As the exception says - we don't support making HTTP callouts in triggers.  You could put this callout in an Apex future request and invoke that future request from the callout.

This was selected as the best answer
yuvrajindiayuvrajindia

Thanks for Reply i just added @future and it's now woking.

 

 

yuvrajindiayuvrajindia

Thanks to reply

 

yes i use here @future and now it 's submitted but still xml post is not working... :(

 

 

Any one help me please.

dkadordkador

 What's the error message?

yuvrajindiayuvrajindia

No Error message  :(

SuperfellSuperfell

How is it not working ?

yuvrajindiayuvrajindia

xml is not posting ...when i post  this xml from url it send me sms but when i post it from http request it's not send me sms.

 

SuperfellSuperfell

The respose to the POST probably contains some useful info that you need to look at.

dkadordkador

Also, since you make your callout asynchronously, you're not going to get inline errors.  You're probably going to have to add debug statements and then look at the debug logs.