You need to sign in to do that
Don't have an account?

Query of LOB fields Exception heap usage to exceed limit
Hi
I have written one trigger on Feedcomment. It's working fine on sandbox but when we move into the production
some new exception is coming i.e.
System.LimitException:Query of LOB fields caused heap usage to exceed limit.
The error is coming on this SOQL query:
List<UserFeed> usefd = [SELECT Id, Type, body, ContentFileName, createdbyId, InsertedById, ParentId, Body, Title, ContentData, FeedItemId,(SELECT CommentBody, InsertedById, FeedItemId FROM FeedComments ) from UserFeed where CreatedById =: feedcommentid ORDER BY CreatedDate ];
Does any one know what type of error is this.
Thanks,
Rajiv
Just got the official word from salesforce.
The heap size changes in Winter '12 are being rolled back tonight. This means two things:
(a) heap size limits will be returning to the old 3/6 limits
and
(b) heap calculation will *also* be returning to the old method of one-object-at-a-time within the SOQL for loop instead of all-objects-at-once.
All Answers
This sounds like you are pulling back more information that can be stored in the available heap space, which is 3Mb. I'd imagine its because you are retrieving the ContentData field, which returns the base 64 encoded contents of a file.
Same issue we are identifying with our existing applications now. Is this because of new winter release done by Salesforce???
No , I tried to find out in Winter 12 Release and not documented anywhere that Heap Size Reduced 3 MB as earlier it was 6 MB. Now documented is something like this.
Higher Governor Limits in Some CategoriesThe following governor limits are higher for Batch Apex and future
• Total number of SOQL queries issued is 200 instead of 100.
•Total number of executed code statements is 1,000,000 instead oIn addition, the heap size limit is now doubled and is raised for Batch Apex And Future Methods .
•Total heap size is 6 MB.
•Total heap size for Batch Apex and future methods is 12 MB.
I am also fed up the running code is **bleep**ed up.
This is a regression in Winter '12.
It used to be the case that heap was only allocated / counted when you pulled an object off its [select] statement, so you could easily do this:
Then you are OK as long as you don't leave the Body on your heap across iterations - in other words, the above code works great in all prior releases.
However, in Winter '12, the entire result set is counted against your heap right away, so the query itself blows the heap.
That means the only way to query against multiple Attachments - even if you have a good strategy for disposing of them within your SOQL loop - is to use row-at-a-time selects.
Can someone at Salesforce verify this change is intended, and we should all alter our code accordingly?
Note - this might actually be intended. If SFDC's appservers do, in fact, pull all the bits from the DB in one shot, and as a result were blowing their own heaps due to our Apex code, then I could understand that they might have to change the point of calculation to push the problem into our laps. But row-at-a-time selects aren't great either; the better solution would be to make the appserver behavior match the old calculation behavior...
Salesforce support, I have opened case 06429984 to track this issue.
A couple things:
a. I'm on the phone with salesforce partner support, and they inform me that the heap size limits in the Winter '12 documentation is wrong, and is actually still at the old limits (3 inline, 6 for future & batch). I don't know whom to believe, however.
b. Just got an email from a PM at salesforce, saying that the heap size changes are being rolled back tonight. I think that means that the heap size limits WILL be returning to the old 3/6 limits, but the heap calculation will *also* be returning to the old method of one-object-at-a-time within the SOQL for loop instead of all-objects-at-once.
c. Here's how to reproduce:
Take note of the contact ID so printed, and then run this code:
Just got the official word from salesforce.
The heap size changes in Winter '12 are being rolled back tonight. This means two things:
(a) heap size limits will be returning to the old 3/6 limits
and
(b) heap calculation will *also* be returning to the old method of one-object-at-a-time within the SOQL for loop instead of all-objects-at-once.
What is mean 3/6 Limit.
3 MB Total heap size is ? And
6 MB Total heap size for Batch Apex and future methods ?
?????
ANd what They Rolled backed as I had mentioned in my Above Post.
New Limits are .
•Total heap size for Batch Apex and future methods is 12 MB.
Higher Governor Limits in Some CategoriesThe following governor limits are higher for Batch Apex and future
• Total number of SOQL queries issued is 200 instead of 100.
•Total number of executed code statements is 1,000,000 instead oIn addition, the heap size limit is now doubled and is raised for Batch Apex And Future Methods .
•Total heap size is 6 MB.
•Total heap size for Batch Apex and future methods is 12 MB.
And what was the problem in this release by reason they rolled backed ????
Yes, by "3/6" I meant 3 for normal apex, 6 for batch & future. I don't know if they rolled back any other limits.
I imagine the problem that I pointed out (counting all objects in a SOQL for loop against the heap up front, instead of one-at-a-time in the body of the loop), may be part of the reason for rollback. That broke a lot of code that used to work.
I confirmed the rollback has occurred and SOQL for loops are working again:
Outputs:
Whereas before it would throw the exception immediately after the "pre loop" debug line. Note that final "post loop" heap is still large, but (I suspect) it's only because the dead Attachment reference hasn't been garbage collected yet.
Thanks jhart,
I got your point. Thank you very much again.