Skip to main content

#GovernorLimits4 diskutieren mit

I spent weeks debugging an obscure Salesforce internal error that made no sense. 

System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop 

The query had 5 child records with a Long Text Area field and a few hundred records in a completely separate subquery with only Id selected. 

No LTA. No RTA. Just IDs. 

Yet the query was failing. 

After opening a case with Salesforce Support and escalating to the Product Team, I got the official answer: 

"Working as Designed." 

The Apex runtime applies a shared CLOB budget across ALL child subqueries — even ones with no LTA/RTA fields. The reasoning: heap safety across the entire query tree. 

I wasn't satisfied with that answer. So I ran dozens of tests across different field sizes and record counts and reverse-engineered the internal formula. 

Here's what the runtime actually does: 

Step 1 — sum up all declared LTA/RTA field lengths anywhere in the query (parent + every subquery) 

Step 2 — derive a total children row budget: 

 

FLOOR( 1000 / POW(2, MAX( CEILING(LOG2(totalClobLength / 32768)), 0 )) ) 

Which produces this table: 

totalClobLength | Row budget 

--------------- 

256 B - 32 KB | 1,000 

32–64 KB | 500 

64–128 KB | 250 

128–256 KB | 125 

256–512 KB | 62 

 

Both empirical thresholds I observed matched this formula exactly. 

Here's the flaw. 

The row budget is calculated from LTA/RTA field sizes — and then applied to ALL child records across ALL subqueries, including those that select only Id. 

A subquery like (SELECT Id FROM Children2__r) contributes zero bytes of CLOB content. 

But each of its records still consumes one slot from the budget. 

The budget is asking "how many rows can we safely load given the CLOB volume?" 

Then it counts rows that carry no CLOB data at all toward that answer. 

The fix is straightforward: 

Apply the CLOB row budget only to subqueries that actually select LTA/RTA fields. 

Records in (SELECT Id FROM ...) should not count against a heap limit derived from text field sizes. 

I've submitted this to IdeaExchange: 

"Fix Design Flaw in internal totalClobLength calculation" 

If you've ever hit this error in a multi-relationship query — or you work with contracts, documents, or any domain with rich-text fields on parent objects — please vote. 

https://ideas.salesforce.com/s/idea/a0BHp000017Jka1MAC/fix-design-flaw-in-internal-totalcloblength-calculation

 

#Salesforce #Apex #SalesforceArchitect #SalesforceDeveloper #GovernorLimits

4 Kommentare
0/9000

Is there a specific app that people have found useful when monitoring their API usage w/in a 24 hour window? We hit a limit a couple months back and we need to monitor our system better. What is the best way to manage/report performance analysis and identify the longest running jobs/synchronous calls? What is the best way to identify the top 10 offenders of our internal making?

 

#API  #GovernorLimits  #Trend Analysis

1 Antwort
  1. 28. Feb. 2024, 00:18

    Hi @James Hartless ,

     

    Check Your Event Monitoring Logs If Available

     

    If you’ve purchased the stand alone Event Monitoring Logs add-on or have it through Platform Shield, great! You have access to lots of valuable information. Using the Salesforce Event Log File Browser, which in my head have nicknamed ELF, one can browse your org’s events including the ConcurrentLongRunningApexLimit event and see each time it occurred and for whom. Concurrent Long-Running Apex Limit Event Type Documentation

     

    https://metillium.com/2020/10/salesforce-concurrent-long-running-apex-limit-troubleshooting/

     

    Limits(REST API )

     

    Lists information about limits in your org. For each limit, this resource returns the maximum allocation and the remaining allocation based on usage.

    https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_limits.htm

0/9000

Hi All, I have been reviewing the platform event usage of an org and I noticed that limit on 'Event Publishing' was more than 500,000 a day while the limit of the org is 250,000 as mentioned below.

"Event Publishing: maximum number of event notifications published per hour : 250,000"

Do you know if this limit is a soft limit as we have not noticed any process failing due to the breach of this limit.

#Platform-events #GovernorLimits

4 Antworten
  1. 29. Nov. 2023, 07:16

    These are a mix of events including the change type as well as custom platform events. These are regarding the 'publish' events. Most of the instances are of CHANGE_TYPE for record changes of object like account.

0/9000

Hi, I have a batch apex that retrieves an object, that will update data in 5 different objects. I am getting heap issue. I used Limits.getHeapSize(); I cleared list after inserting(accList.clear()). In debug log with getHeapSize() shows similar size, not much difference. But in anonymous there is a change.

 

I am unable to find what is the exact heap size, where it get exceeded. Debug logs are of no use. I also tried queueable apex to insert a list and clear it later.

 

How to debug properly for this issue?

#Batchable #Batchapex #Salesforce Developer #GovernorLimits #Apex

2 Antworten
  1. 21. Okt. 2023, 16:23

    @AMAN GARG I Created a sample batch apex with perfect optimization. But the issue is, it shows the same heap size in Limits.getHeapSize(); Probably We can say it is async, but how to exactly know where the heap gets exceeded?

0/9000