How to open a VF page from future callout method?
I am working on requirement , i will make a callout to external system to get the lead details , before i insert the lead details i need to display it in VF page for confirmation?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
What you are looking for is not possible to open a page from the async call. You may do the following.
1) Implement VF page for edit and insert and do web service call.
2) Do a future call and update record asynchronously
3) if it is long running call use this
This question is very close to being an XY-problem (that is, you have a problem X, and you've chosen a solution Y. You're asking about how to make your solution Y work instead of asking how to solve problem X).
@future is not the right tool for the job here, at least not for the problem as worded in your question.
@future is meant to be fire-and-forget.
@future returns no data, and provides no indication of when it has finished. You could try to query the
AsyncApexJob object (which will contain very limited information about the
@future call), but trust me when I say that's not a road you want to go down.
Instead, the feature you're looking for is called apex continuations. The key feature that makes continuations suited for this task is that a continuation allows you to specify a callback method that is executed when your callout finishes (and that callback method can cause a page refresh to display the returned data).
Beyond that, another option I could suggest is to abandon trying to display data to the user before inserting records into Salesforce. Instead, you could simply insert records using data from your callout (a task for which
@future is well suited) and use a picklist field, or different record types to distinguish between records that need to be reviewed and those that have been reviewed. You would likely need to prompt your users to review records from time to time, but making a listview to show which records need review (based on either a picklist field or a record type) is quick and simple.