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
MattWelchMattWelch 

Query of LOB fields is causing an exception

This is a post with a bunch of very closely-related questions. First, the general problem:

 

We've got an Apex method grabing a bunch of Attachments, and putting their body and data into a bunch of EmailFileAttachments, which are then sent right out. This method has worked great for over a year, without a single error. Just this past weekend, though, we started to get a bunch of these errors:

 

Query of LOB fields caused heap usage to exceed limit.

 

We've narrowed it down, and figured out that any group of Attachments with total body size of over 3MB or so is causing this error. So these are the questions.

 

1: Why are we just now starting to get this error, when in the past I know we've sent up to 9 or 10MB worth of attachments? Is it something to do with Winter 12, which just hit this org this weekend?

 

2: Why, in the past, have we been able to queue up 10MB worth of attachments and send them without running into the 3MB heap size limit?

 

3: Why are we having trouble with 3MB now, when it seems like the heap size has been increased to 6MB? (6MB would still be a problem, of course, as we should be able to send 10MB worth of email attachments.)

 

Here's the code. The exception is occuring right at the SELECT:

 

Messaging.EmailFileAttachment[] attachments=new List<Messaging.EmailFileAttachment>();
for (Attachment a:[select id, body, contenttype, name from Attachment where id in :selectedAttachmentIds]) {
	Messaging.EmailFileAttachment ef=new Messaging.EmailFileAttachment();
	ef.setBody(a.body);
	ef.setContentType(a.ContentType);
	ef.setFileName(a.name);
	ef.setInline(false);
	attachments.add(ef);
}