My Scenario is I have a search page.when I click on search then I got 500 records in 50 pages( Here Pagination is using…Means 10 records per each page). what I am doing here is when click on Download button then only that 10 records are getting saved in Excel.But I want total 500 records in Excel. Please guide me how to achieve this..
-
Without pagination how many records will available in a page?– user5257Commented Jan 30, 2014 at 18:40
-
I created two VF pages and one controller..everything working fine. I need all records need to get saved in Excel.Only first page records are saving in Excel.– user5257Commented Jan 30, 2014 at 18:43
2 Answers
You can use readOnly annotation in controller and @readOnly annotation in your controller/extn to process more than 1000 records in your list page.
Here is a sample code you can use,
Step1: Create a controller/extn to get the records with your personal limit and make it readOnly to expand your SOQL limits.
public class contactslistExtn {
public static List<Contact> mycontacts = null;
public contactslistExtn(ApexPages.StandardSetController controller) {
}
@readOnly
@RemoteAction
public static List<Contact> getMycontacts(){
if(mycontacts == null){
mycontacts = [select id, name, mailingCity, phone from contact limit 1000];
}
return mycontacts;
}
}
Step2: Create a new VF page just to create the excel:
<apex:page standardController="contact" extensions="contactslistExtn" recordSetVar="contacts" contentType="application/vnd.ms-excel#mycontacts.xls" readOnly="true">
<apex:pageBlock >
<apex:pageBlockTable value="{!myContacts}" var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.MailingCity}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Step3:
Create a list button with Javascript (window.open("/apex/contactlists", "_blank");
) or a salesforce to open the create VF page (contactlists).
Step4: add it to your list page "search layouts".
You have to create VF page without paging. But I don’t think that it is perfect solution. Standard salesforce generated excele file still consist some html tags. So In my opinion best solution will be generate CSV file. Such file can be still useful as data backup and if you open it in for example Calc you can work with it like with spreadsheet.