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
Geetha saiGeetha sai 

Export selected records by checkboxes in table view

Hi ..
Is there any way that I could export selected rows from a table view ? for example if there is a table with 10 records , I want to export the first , third and fourth (selected with checkbox) ?
I tried to search about it but I'v got no clue .. did I miss something ?
Palani_ChinnasamyPalani_Chinnasamy

Hi Geetha,

You can use wrapper class to add Checkbox to selected rows. And split the seleceted rows only into new list !  
refer the below sample codes for wrapper classes. 

Public  class exportSelectedAccount {

    //### SELECTED ACCOUNT SHOWN BY THIS METHOD
      public void getSelectedRows(){
     selectedAccounts=new list<account>();
     
      for(wrapaccount wrapobj:wrapaccountlist){
           if(wrapobj.isSelected==true){
           selectedAccounts.add(wrapobj.accn);
           }
            
         }
      }
      
  //##THIS IS WRAPPER CLASS
   // account and checkbox taken in wrapper class
   
   public class wrapaccount{
    
    public account accn{get;set;}
    public boolean isSelected{get;set;}
     
       public wrapaccount(account a){
     
         accn=a;
         isselected=false;
       }
  }
}

Please try let us know if you have doubt! 
JSingh9JSingh9
I think You need to build a VF page for this
Geetha saiGeetha sai
Thanks a lot Palani....But what my requirement is I need a custom button whenever the selected records are checked those  records will be downloaded...Any help will be appreciated...
Palani_ChinnasamyPalani_Chinnasamy

Hi Geetha,

I have done same for my current project ! Surely I can help you. Here is the same code for export to excel. 

<apex:page controller="ExportToExcelMultipleSheets" contentType="txt/xml#myTest.xls" cache="true">
    <apex:outputText value="{!xlsHeader}"/>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
  <Styles>
   <Style ss:ID="s1">
   <Alignment/>
   <Borders/>
   <Font ss:Bold="1"/>
   <Interior/>
    <NumberFormat/>
    <Protection/>
     </Style>
   </Styles>
  <Worksheet ss:Name="Accounts">
  <Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Row>
 <Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
 </Row>
  <apex:repeat value="{!accountList}" var="account">
  <Row>
 <Cell><Data ss:Type="String">{!account.name}</Data></Cell>
 </Row>
 </apex:repeat>
 </Table>
 </Worksheet>
 <Worksheet ss:Name="Contacts">
  <Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Column ss:Width="280"/>
  <Column ss:Width="330"/>
  <Row>
  <Cell ss:StyleID="s1"><Data ss:Type="String" >Contact Name</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Email</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
  </Row>
  <apex:repeat value="{!contactList}" var="contact">
  <Row>
  <Cell><Data ss:Type="String">{!contact.name}</Data></Cell>
  <Cell><Data ss:Type="String">{!contact.email}</Data></Cell>
  <Cell><Data ss:Type="String">{!contact.account.name}</Data></Cell>
   </Row>
  </apex:repeat>
</Table>
 </Worksheet>
</Workbook>
</apex:page>

and Write a controller to get select list and pass to visualforce pages.

Do try with help the code 
Geetha saiGeetha sai
Palani, If possible can you please send your contoller(ExportToExcelMultipleSheets) code.

Thanks in advance.
 
Palani_ChinnasamyPalani_Chinnasamy
Hi Geeta,

This is sample code only, for your requirement, your need to genarate new list with selected rows.
 
public with sharing class ExportToExcelMultipleSheets {

public List<account> accountList{get;set;}
public List<contact> contactList{get;set;}
public String xlsHeader{
    get{
        String strHeader = '';
        strHeader += '<?xml version="1.0"?>';
        strHeader += '<?mso-application progid="Excel.Sheet"?>';
        return strHeader;
    }
}
public ExportToExcelMultipleSheets(){
    accountList = [select Name,Id from Account LIMIT 10];
    contactList = [SELECT id,Name, LastName, Account.Name, Email FROM Contact WHERE Email != '' AND Account.Name != '' LIMIT 5];
}
public Pagereference exportAll(){
    return new Pagereference('/apex/exportAll');
    }
   }

Thanks
Palani
 
Geetha saiGeetha sai
Thanks for the quick response.See the below image..In that export selected custom button is there.Whenever i selected some selective records after click on that custom button(Export Selected)those rselected records only  will be downloaded.User-added imageloaded...
Palani_ChinnasamyPalani_Chinnasamy

Hi Geetha, 

Yes, to do the operation please refer my first command ! 

 

Geetha saiGeetha sai
Thank you a lot palani..Let me do.Still i have any concerns i will approach you.