+ Start a Discussion
sfdc18sfdc18 

Open Visualforce Page through @future method

Hi,

I have a @future method Display().
I want to open visualforce page after executing callout code from future method.

@future(callout=true)
public static void display()
{
//callout code
//after this callout code, this method should open vf page
}

I am calling this future method thro' after insert trigger.
Shaijan ThomasShaijan Thomas
<apex:outputPanel id="tstpopup">
            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
             <apex:actionStatus id="loadingFilter">
            <apex:facet name="start">
                <img src="{!$Resource.AjaxAnimation}" />
                &nbsp;&nbsp;
                <FONT COLOR="black" SIZE="2"><b><i>Processing....</i></b></FONT>
                <br/><br/>
            </apex:facet>
        </apex:actionStatus>
                       <apex:outputPanel style="height:200px;overflow:auto;" id="inpanel" layout="block">
                       //put your code here
                        </apex:outputPanel>
            </apex:outputPanel>
        </apex:outputPanel>
		//displayPopUp value set true or false in your code

try somthing like this
Thanks
Shaijan
Gil GourévitchGil Gourévitch
Hi,
This seems not to be possible :
when you call a future method, there is no return (void return type), and the navigator is not the client, the method is executed "when Salesforce has available resources" see SF doc about future anotation here (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm).
So the platform executing the @future method cannot know who to send the response, and so the redirection.

Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
sfdc18sfdc18
Hi Gil,

What should I do then.
Actually my scenario is, whenever callout fails it should display some custom error message on visualforce page

Thanks
Gil GourévitchGil Gourévitch
I think you have to change the type of your Display method, and not calling it from a trigger.
If the you are in a VF page with a controller, you can make the callout directly into the controller, and display the message (you are in a controller context, so your browser is the client) in VF page with <apex:messages /> tag.
Then you save the record only if the callout is successfull.

Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !