+ Start a Discussion
Arjun y 7Arjun y 7 

How to send an email as attachment more than 20000 records via csv file in salesforce


I have a list contains 27000 records. I need to send these records as an attachment via email. 

While i am running the class, receiving heapsize limit error. I can able to send attachment for 5000 records not for above 20000 records.

Can any one please help me to sort out this.

Rajiv Penagonda 12Rajiv Penagonda 12
You have hit one of the Salesforce hard limits. Heap size is generally encountered when there is a design issue.

20000+ records are huge to process in apex and attach in an email. My suggestion is that you may redesign your solution. Instead of providing an attachment, provide your users with a link in email to a visual force page. Create a VF page to query and show these 27000 records and then render that VF page as "excel".

Hope this helps.