3

First of all: what are LOB fields?

Secondly: I have a complex apex automated process in which I need to make an exact copy of an Asset object (all of its fields). To do this I created a method that describes and lists all of the fields, so I can create and edit the copy.

When issuing the Database.query statement, I'm getting an exception:

System.LimitException: Query of LOB fields caused heap usage to exceed limit. 

Why does this happen?

On the debug log I get plenty of space in the synchronous transaction (6mb):

16:45:38:155 USER_DEBUG [87]|FINE|Heap limit: 6000000
16:45:38:156 USER_DEBUG [88]|FINE|Heap usage: 5316
3

LOB simply means "Large Object" fields. They refer to long text areas (those greater than 255 characters), be it standard or custom, such as Description or MyCustomLongText__c. Note that heap isn't calculated or checked in real-time, so even though you may have had plenty of heap, this error is stating that the query itself exceeded the heap. You can generally fix this by removing the fields, or using a for-query loop:

for(sobject varName: [SELECT ... FROM ... WHERE ...]) {
  // Do stuff here
}

This is one of the reasons why we do not have a "SELECT *" syntax in Salesforce.

  • So my best bet would be to really determine which fields are absolutely needed to copy, instead of dynamically getting them? – Renato Oliveira Apr 18 at 20:21
  • 2
    @RenatoOliveira Yes. You could still use a Field Set to avoid hard-coding values, and make it easier to add/remove fields, Custom Metadata records, or an approach using describe calls. There's a few options available. – sfdcfox Apr 18 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.