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
Arjun y 7Arjun y 7 

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

Hi,

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.

Thanks
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.