Back to All Events

Chunking to overcome the Apex heap governor - Ray Dehler & Evan Heathcock

  • Events on Jackson 245 East Jackson Street Phoenix, AZ, 85004 United States (map)

The dreaded Salesforce governor! Have you ever needed to work with large files in apex, only to be harshly and suddenly be shut down by the apex governor due to HEAP_LIMIT_EXCEEDED?

Consider this customer use case: Salesforce should callout to retrieve a 20MB file using a service account credentials for authentication and make it available to download to the user. A client-side callout is problematic for several reasons, mainly security. A callout from apex would halt attempting to manage a file of this size.

Enter the chunking pattern! By retrieving a heap-manageable chunk of the file at a time and combining on the client side, we are able to work within the apex heap limits.

In this session we review the problem statement, review several options to overcome the apex heap, showcase the chunking pattern, show its elegance and simplicity, and finally review a customer implementation recently where this was used.