Nowadays excel files are very common and easy to share with other people. So there is a quite high demand in salesforce as well, as we all know data loader in salesforce uses csv files to import the files but we need a functionality that will generate an excel file using the opportunity object record data which gives us the option to export the excel as well.
Create a VF page Name : ' ExportExcel.vfp '
{!xmlheader}
1
16000
20480
400
400
False
False
Name |
Amount |
StageName |
CloseDate |
{!opp.Name} |
{!opp.Amount} |
{!opp.StageName } |
|
0
1
1
2
3
False
False
Create an Apex class Name : ' ExportExcel'
public class ExportExcel {
public List oppWrapper{get; set;}
public String xmlheader {get;set;}
public String endfile{get;set;}
private ApexPages.StandardController controller;
public ExportExcel(ApexPages.StandardController controller){
this.controller = controller;
xmlheader ='';
endfile = '';
oppWrapper = new List();
try {
for(Opportunity oppty : [SELECT Id, Name, Amount, StageName , CloseDate FROM Opportunity where Id =: controller.getId()]){
OpportunityWrapper oppWrp = new OpportunityWrapper();
oppWrp.Name = oppty.Name;
oppWrp.Amount = Oppty.Amount;
oppWrp.StageName = Oppty.StageName;
oppWrp.CloseDate = Oppty.CloseDate;
oppWrapper.add(oppWrp);
}
} catch(Exception ex){
System.debug('Error : ' + ex.getMessage() +' '+ ex.getCause() + ' '+ ex.getLineNumber());
}
}
public class OpportunityWrapper{
public String Name{get; set;}
public Decimal Amount{get; set;}
public String StageName{get; set;}
public Date CloseDate {get; set;}
}
}
Create a button Name : ‘ Opportunity Download ‘
Step 1 : Go to Opportunity object. Click ‘ Button Links and Actions ‘
Step 2 : Enter Label ‘ Download Opportunity ‘.
Step 3 : Select Display Type : ‘ Detail Page Button ‘ .
Step 4 : Select Behavior : ‘ Display in existing window with sidebar ‘
Step 5 : Select Content Source : ‘ Visualforce Page‘
Step 6 : Click on Save .

Add Download Opportunity in Salesforce Mobile and Lightning Experience

Download opportunity

