+ Start a Discussion
Ravi K 47Ravi K 47 

Download selected records into excel in salesforce

Hello All,

I have a requirement to download only the selected child records (Not all child records )into an excel file in salesforce.

Lets assume,take Account and Contact
Account	Contacts
India	Delhi,
	    Karnataka
	    Chennai,
	    Andhra Pradesh
Now my requirement is to select few contacts only (lets assume only Delhi and Chennai )  for Account : India then only the selected records to be download into excel.

I can download all the contacts but not the selected records .Below is the code reference for all contacts
<apex:page standardController="Account" contentType="application/vnd.ms-excel#contacts.xls">
    <apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!account.Contacts}" var="contact">
            <apex:column value="{!contact.Name}"/>
            <apex:column value="{!contact.MailingCity}"/>
            <apex:column value="{!contact.Phone}"/>
            <apex:selectOption itemLabel="C" itemValue="f"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


Could you please check and let me know if you require any additional information.

Thanks,
Ravi.
 
DevADSDevADS
Hey Ravi,

Create two VF pages 
1. Create a staging page for the user to select the Contact records with "Export" button.
2. Create another VF page setting up content type to "application/vnd.ms-excel#contacts.xls", Like you have done in your question.

Keep the same controller for both the pages and once a user clicks on "Export" button then redirect it to the second page and show the selected items.

Do let me know if you've any more queries.

 
Ravi K 47Ravi K 47
Hi DevADS,

Can you please explain the scenario little bit futher

1: You mean to create one VF page to select the contact records .If yes, please provide some reference if you have any ?
2:  For 2nd point the code is already designed right? please confirm on this?

Thanks,
Ravi