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

How to get around System.LimitException: Query of LOB fields caused heap usage to exceed limit. (in Apex)
Hello, I keep getting an ApexApplication email saying:
Failed to invoke future method 'public static void UploadDocument(String)' on class 'S3Controller' for job id '7073l0000FSMaBy'
caused by: System.LimitException: Query of LOB fields caused heap usage to exceed limit.
The line of code that is causing the error is this:
List<ContentVersion> versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true];
How can I change my code so that if that error comes up, I still query the files but ONLY query the 1st file (as a way of avoiding the error)?
I TRIED this:
List<ContentVersion> versions = new list<contentversion>();
try{
versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true];
}
catch (exception e){
versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true limit 2];
}
BUT it didn't work. I am still getting the same ApexApplication error email.
Failed to invoke future method 'public static void UploadDocument(String)' on class 'S3Controller' for job id '7073l0000FSMaBy'
caused by: System.LimitException: Query of LOB fields caused heap usage to exceed limit.
The line of code that is causing the error is this:
List<ContentVersion> versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true];
How can I change my code so that if that error comes up, I still query the files but ONLY query the 1st file (as a way of avoiding the error)?
I TRIED this:
List<ContentVersion> versions = new list<contentversion>();
try{
versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true];
}
catch (exception e){
versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true limit 2];
}
BUT it didn't work. I am still getting the same ApexApplication error email.
Hi,
I hope these links will help you.
https://developer.salesforce.com/forums/?id=906F00000008zoxIAA
https://salesforce.stackexchange.com/questions/239779/first-error-query-of-lob-fields-caused-heap-usage-to-exceed-limit
https://www.eigenx.com/blog/2017/1/23/solutions-to-fix-apex-heap-limits
Thank You
All Answers
Hi,
I hope these links will help you.
https://developer.salesforce.com/forums/?id=906F00000008zoxIAA
https://salesforce.stackexchange.com/questions/239779/first-error-query-of-lob-fields-caused-heap-usage-to-exceed-limit
https://www.eigenx.com/blog/2017/1/23/solutions-to-fix-apex-heap-limits
Thank You