I wrote batch class which creates a excel file in documents folder. But my problem here is when the size of excel reaches 5MB then the heap size error is shown and batch fails after certain records(here I have around half million records but in excel got around 80K). How can I overcome the issue friends. I think I have to check the excel size after every batch and if it is greater than 5MB then a new file needs to create- but not able to get the exact logic for this. Waiting for your reply friends!!!! here is my code where I am creating document:
list<Document> doc= [select id,name,FolderId,body from Document where name ='PersonAccBackup.csv' limit 1];
if(doc.size()>0){
string lastbatch = doc[0].body.toString();
doc[0].FolderId = '00l800000016NkM';
doc[0].body = blob.valueof(lastbatch + deletedAccountIds);
update doc;
deletedAccountIds = '';
} else {
Document doc1 = new Document (Name = 'PersonAccBackup'+'.csv');
doc1.Description = '';
doc1.FolderId = '00l800000016NkM';
doc1.Body = Blob.valueOf(deletedAccountIds);
insert doc1;
deletedAccountIds = '';
}
}
Attribution to: sfdcpavan
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32085