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
DoondiDoondi 

"export to excel" button on custom list view page

Hi,
I Have custom visualforce page for List views (example : ALL views, Major views etc...)
Now I want to button to export for  Major views.
[if user select all views and click on export button, then I need all records to download, 
If user select Major views and click on export button then I need Major views records]

Any tips and liks on how I can achieve this ?
Best Answer chosen by Doondi
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi

Onclick export button - redirect to other vf page which prints the existing vf page :

Example:

Call a method 'export' onclick the button which redirects to other vf page:
public pageReference export()
    {
         PageReference pageRef = new PageReference('/apex/secondVFpageName');
		return pageRef;
    }

In the second vf page you can simply add the below code to print the content of first vf page:
<apex:page contentType="application/vnd.ms-excel#AccountListTable.xls">
    <apex:include pageName="FirstVfPage"/>
</apex:page>




 

All Answers

Raj VakatiRaj Vakati
Use list view api to get the data

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_listview.htm
 
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi

Onclick export button - redirect to other vf page which prints the existing vf page :

Example:

Call a method 'export' onclick the button which redirects to other vf page:
public pageReference export()
    {
         PageReference pageRef = new PageReference('/apex/secondVFpageName');
		return pageRef;
    }

In the second vf page you can simply add the below code to print the content of first vf page:
<apex:page contentType="application/vnd.ms-excel#AccountListTable.xls">
    <apex:include pageName="FirstVfPage"/>
</apex:page>




 
This was selected as the best answer
DoondiDoondi
Thanks guys!!