+ Start a Discussion

Issue with @Future method not getting called

Hello all.


I'm rather new to posting on the Discussion Boards, but I have found them extremely useful in cutting my teeth on force.com development.  Big thanks to everyone who has helped me out so far...


I have a general question about future methods (ie Callouts):


I have a trigger in my sandbox that calls a method which calls out to a webservice I'm hosting.  This was working great yesterday.  The calls were almost instantaneous.  This morning I start testing again, and I get the following error:



Failed to invoke future method 'public static void makeCallout(String)' Debug Log: System.CalloutException: Read timed out



Afterwards, everytime I called the method from my trigger, nothing would happen.  No error messages, no activity on my web service, nothing.  I even put some System.Debug lines in my method, and they never show up in the System Log.  Also, I have in no way reached the 200 per licence per 24 hours limit.  In addition, my web service is working great.  I can call it using a SOAPUI client.


I did notice in the Montoring section under Apex jobs, that there is a record for every single attempt I made today, showing Job type as Future, Status Completed and Errors 0.  So it appears that the method is getting called, but not being processed.  Is it possible that the sandbox is queuing these up for some reason today?  Can anyone point me in the right direction?


Thanks in advance!!!



David VPDavid VP

a Read Timed Out message usually means that your webservice isn't responding within 10 seconds. Are you sure you're connecting to the correct endpoint ? Perhaps it's gotten slow ?


Have you tried connecting to your webservice with a SOAP testing tool (SOAP UI, Eclipses Web Services explorer,...) to see if your web service is answering ?


Hi David.  Thanks for the reply.


Actually yes, I have called it using SOAP UI and the service works fine.  And I only got the Read Timed Out message 1 time.  Afterwards, I never received another message.  The trigger executes fine, but it's not calling my method.  If I remove the @future annotation and comment out the http calls, the method gets called.  So it appears to have an issue with @future methods.


Also, at this point, it's been well over 24 hours since it last ran, so the limits shouldn't be be a factor.

David VPDavid VP

Then something else must be wrong.

Can you post your code (trigger + class with @future) ?




Hi David, here's my code:



trigger runWebService on Opportunity (after update) { for (Opportunity opp : Trigger.new) { System.Debug('Processing ' + opp.ID); wlQuotesWebService.makeCallout(opp.ID); } }



Apex Class:

public class wlQuotesWebService{ @Future(callout=true) public static void makeCallout(String opportunityID){ System.Debug('*******Starting Callout*******'); // Instantiate a new http object Http h = new Http(); // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint HttpRequest req = new HttpRequest(); //get the Opportunity Opportunity opportunity = [Select Id, Contact__c, OwnerId, Name, Rep_1__c, Rep_2__c, Rep_3__c,Split_1__c,Split_2__c, Split_3__c, Source_code__c, CloseDate, Probability, Vertical_Market__c, StageName, Competitors__c from Opportunity where Id = :opportunityID]; // The webservice url - Pass in the endpoint to be used using the string url String url = 'url to web service'; String soapXML; soapXML = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:quotes.salesforce.companyname.com">'; soapXML += '<soapenv:Header/>'; soapXML += '<soapenv:Body>'; soapXML += '<urn:oppID>' + opportunity.ID + '</urn:oppID>'; soapXML += '<urn:contactid>' + opportunity.Contact__c + '</urn:contactID>'; soapXML += '<urn:ownerid>' + opportunity.OwnerId + '</urn:ownerid>'; soapXML += '<urn:oppname>' + opportunity.Name + '</urn:oppname>'; soapXML += '<urn:rep1>' + opportunity.Rep_1__c + '</urn:rep1>'; soapXML += '<urn:rep2>' + opportunity.Rep_2__c + '</urn:rep2>'; soapXML += '<urn:rep3>' + opportunity.Rep_3__c + '</urn:rep3>'; soapXML += '<urn:split1>' + opportunity.Split_1__c + '</urn:split1>'; soapXML += '<urn:split2>' + opportunity.Split_2__c + '</urn:split2>'; soapXML += '<urn:split3>' + opportunity.Split_3__c + '</urn:split3>'; soapXML += '<urn:sourceCode>' + opportunity.Source_code__c + '</urn:sourceCode>'; soapXML += '</soapenv:Body>'; soapXML += '</soapenv:Envelope>'; req.setBody(soapXML); req.setEndpoint(url); req.setMethod('POST'); System.Debug(soapXML); //Basic Authentication String username = 'username'; String password = 'password'; Blob headerValue = Blob.valueOf(username+':'+password); String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); req.setHeader('Authorization', authorizationHeader); // Send the request, and return a response HttpResponse res = h.send(req); XmlStreamReader reader = res.getXmlStreamReader(); //TODO - parse XML Response } }


Also, just for grins, I created a new Apex class & @Future method that simply had a System.Debug('Hello World'); and it never printed to the log.  It's as if I've been cut off from @Future methods completely.


Thanks again for your help.


I am having the same problem, however it doesn't happen everytime, and the web service I am calling works fine as expected.


It is just annoying to receive the Apex script exceptions.  I'd like to find out why this happens.



Failed to invoke future method 'public static void GenerateActivationCodeAsync(Id, String)'Debug Log:System.CalloutException: IO Exception: Read timed out




I increased value of webservicesoap.timeout_x to 10 seconds, but the problem still occurs. 

I have similar issue, even if I comment the callout that function with @future annotation doen't execute. If I remove @future, it works fine.


What's the problem with '@future'? Any suggestion?





I have this same issue as well. My flow is:


1. Trigger fires

2. Method is invoked

3. If i remove the @future (callout=true) and hide the callout it works (or if I use the debug log it works) but if I leave in the @future nothing works.


Code Snippets:




trigger GAC_IPNResponse on Pay_Pal_IPN__c (after insert, after update) { GAC_IPNResponseClass.GAC_IPNResponseClassCallOut(); }


public class GAC_IPNResponseClass { @future (callout=true) public static void GAC_IPNResponseClassCallOut() { System.debug('Here'); /// CALLOUT LOGIC }





Thanks in advance for any insight/direction!

Message Edited by TinmanDCS2 on 12-20-2009 09:44 AM

I'm experiencing the same behavior. Do you find a resolution to this?



Robert DellagoRobert Dellago
I know this is an old thread but I had this problem and I didn't find any answers.  I put a Try/Catch around the method to reveal the exeception.