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
shshshsh 

how to export data in apex class to excel?

Hi,

I am trying to export the data to excel sheet from apex class.

i know that we can do the export from vocabularies page.but i want that export to be done from apex class.

how can i achieve this?Please help me out.

SFDC_LearnerSFDC_Learner

This is one of the way but not 100% accurate. make sure account names should not contains any commas

 

Document objD = new Document();
List<Account> lstA = [select id,name from Account];
 
objD.name = 'testFile.csv';
String filecontent;
fileContent = 'Id' + ',' +'Name' +'\n';
for(Account objA : lstA){
 fileContent += objA.id + ',' +  objA.Name + '\n';  
}
objD.body = blob.valueof(fileContent);
objD.folderId = UserInfo.getUserId();
insert objD;
basavaraj virupakshappa 3basavaraj virupakshappa 3
how to export data in apex class to excel?