1

I have a MS Excel VF Page that perfectly downloads data. Now in main VF Page I am having a remote action static method called using vf remoting from button on main page.

From that method I need to call the Excel VF Page. Unfortunately, currently it is failing as I see MS Excel VF Page is not getting downloaded from main page.

Can someone please help me here?

static @RemoteAction method as below, I am trying it.

 @RemoteAction
    public static PageReference XXX(String ABC,String Period,String conditions,string type,String Email) {


....

  ApexPages.PageReference report = new ApexPages.PageReference('/apex/CPATAllBusinessPlanEmail?Conditions=' + conditions + '&ABC=' + ABC+ '&Period=' + Period+ '&Type=' + type);  
report.setRedirect(true);
                return report;
}

1 Answer 1

0

You cannot return Page reference from JS remoting. I mean you can but then it wont give you the desired behavior.

Returning PageReference works when you call it from ways which uses View State. That can be actionFunction,CommandButton, Link, actionPoller and many more....

In your case, Remoting is stateless and doesn't use viewstate. Thusyou are returning page reference record to javascript. Javascript doesnt know what to do with the that pageReference and hence it doesnt redirect.

Can we do something here? Yes you can use Javascript to redirect.

@RemoteAction
public static String XXX(String ABC,String Period,String conditions,string type,String Email) {

    String returnURL ='/apex/CPATAllBusinessPlanEmail?Conditions=' + conditions + '&ABC=' + ABC+ '&Period=' + Period+ '&Type=' + type;  
    return returnURL;
}

And then in your Javascipt use something like

window.location.replace(result); //Result from Remoting call

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .