You need to sign in to do that
Don't have an account?
Scott0987
Wait for an http request to complete before moving on in @future method
I hope this isn't a dumb question but I am still fairly new to apex. I have an http callout in an @ future method. Is there a way to wait for the response before moving on with the rest of the code? Here is my code if that helps.
@future HttpRequest req = new HttpRequest(); req.setEndpoint('http://..... endpoint here); req.setMethod('GET'); Http http = new Http(); HTTPResponse res = http.send(req); JSONParser parser = JSON.createParser(res.getBody()); //I want it to wait here for the response before moving on. while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){ String fieldName = parser.getText(); parser.nextToken(); if(fieldname == 'id') { IDset.add(parser.getText()); } } }
I found a way to do what I want for anyone else who needs this. I put the rest of my code into a different method that was not set with the @future call. Here is the code:
All Answers
I think the very nature of @future means this will not wait. If you want to wait for a return, you can just make an HttpRequest and process its return inline.
I found a way to do what I want for anyone else who needs this. I put the rest of my code into a different method that was not set with the @future call. Here is the code: