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
Shobhit TShobhit T 

Display records in an excel sheet

I have two objects : 1. Assigned_Task__c object
2. Migration_Report__C object 1 is parent of 2

I have a custom button on Assigned Task object Generate Migration List My requirement is when i click on this button all the related records to one particular task are exported to excel sheet. As you can see below i have this button , so when i click on this i want that the information in the related record comes in an excel sheet. Can anyone please help me with this code. Thanks in advance. 

User-added image
ManojjenaManojjena
Hi Shobhit ,

You beed to create a VFpage and a class related to that VF page .
On click of that button you can load that page and get the task Id from the URl and get related Migration_Report records in alist and iterate in the page through repeat and in teh page add contentType="application/vnd.ms-excel Demo.xls"  .

It will down load an excel sheet sheet .If you want to change teh Name dynamically you can .

Thanks 
Manoj

 
Shobhit TShobhit T
Hi Manoj,

Thanks for your valuable time in replying to my question.
I have tried that before like this, but still its not working. If you can share some code that will be helpful.

User-added image
Regards,
Shobhit
ManojjenaManojjena
Hi Shobhit,

is it possible to share your code ,I will update your code .
 
Shobhit TShobhit T
Hi Manoj,

I was able to do it. But what now i require a list view button where i can check the records and click on the Generate Excel button to generate excel of that records only which i have checked.
Like in my accounts view , i check the accounts and click on an excel button i get data for those checked accounts only.
Any idea how i can do this ? Thanks for your time.
ManojjenaManojjena
Hi Shobhit ,

To get the selected record in your page you need to add recSetVar attribute in page ,Once you will add that system will ask to create a constructor with ApexPages.StandradSetController as argument .Then in standardSetController class there is method getSelected() which will give you selected record list .

Try code like below
<apex:page standardController="Account" recordSetVar="Account"  extensions="DiaplaySelectedAccount" >
</apex:page>

public  class DiaplaySelectedAccount{
  public List<Account> accList{get;set;}
  public DiaplaySelectedAccount(ApexPages.StandardSetController cont){
     accList=new List<Account>();
    accList=(Account[])cont.getSelected()){
  }
 }
Let me know any issue .