function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssousanssousan 

How to execute a VF page without being redirected to the page?

I have the following VisualForce page: 

 

<apex:page standardController="Inquery__c" recordSetVar="accvar" contentType="text/csv#filename.csv" >"First Name","Last Name","Email","Qualification"
<apex:repeat value="{!accvar}" var="a">
<apex:outputText rendered="{!NOT(a.Download__c)}">
      {!a.First_Name__c}, {!a.Last_Name__c}, {!a.Email__c}, {!a.Quilification__c}
</apex:outputText>
</apex:repeat>
</apex:page>

 

That I call from a custom button,

Using the Using javascript&colon;

 

window.location = 'apex/Download_data';

 

The button calls the code and it works,

 

But it also redirects me to the VisualForce page,

 

How can I just execute the code,

Without being redirected to the VF page,

 

Thanks

 

 

 

Avidev9Avidev9
Have you tried doing this using pagereference ?
I mean redirecting using pagereference?
ssousanssousan

Could you possibly give me an example how to use PageReference?

 

Thanks

ssousanssousan

I tried this in the javascript window, but it didnt work,

 

 

PageReference pageRef = new PageReference('/apex/downloadonly');

PageReference secondPage = Page.downloadonly;

secondPage.setRedirect(true);

 

Best

Avidev9Avidev9
JS window ?
This is supposed to be apex code/controller method that will invoked using a commandbutton
ssousanssousan

Oh, ok,

I thought you wanted me to use it in the javascript window instead of the window.location = 'apex/Download_data';

 

Let me create a controller,

And try it,

 

Thanks

 

Yoganand GadekarYoganand Gadekar

If you are looking for a pagereference example that opens anew vf page for you, you could probably have alook at this Example For You

 

thanks,