2

We have a class that contains different methods,one of the method uses @future(callout=true) attribute which makes Callout to external site. The response obtained will be used to update the Salesforce database in another method. Since database update method depends on first future call to finish, how to make sure dependent methods are fired at right time?

  • 1
    Future methods are async operations. They have separate transaction so you can not track when they will be finish. Probably you can perform database operation in same future method if it is possible. – Mr.Frodo Nov 30 '17 at 16:32
  • If we will do database update in same future method , there is a issue with code coverage (where every thing is cluttered under one void future method). In order to have right coverage need to divide the work between different methods. – user1585871 Nov 30 '17 at 16:35
  • 1
    you can divide it in seperate methods and call those methods from future. Only a future method can not be called from future method. – Mr.Frodo Nov 30 '17 at 16:39
2

Just put the method call inside the future method:

@future(Callout=true)
public static void callout() {
    response = http.send(request);
    UtilsClass.updateMethod(response);
}

If you're using it on a VF page you can also try the continuation class.

If neither of these work, than I don't believe you'll be able to accomplish your goal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.