20
votes
Accepted
First error: Cannot have more than 10 chunks in a single operation. Please rearrange the data to reduce chunking
Because you wait until the execute() method to query for the records to delete, you are not utilizing the scope parameter (the second parameter of the Database.executeBatch method--in your case, 200) ...
19
votes
Accepted
Do Platform Event Triggers process synchronously? Do they get a fresh set of limits?
Are the subscription triggers processed synchronously or asynchronously?
Aynchronously
Do the subscription triggers get separate limits from the publishing context?
Yes, separate limits from the ...
18
votes
Accepted
Developer Console can SELECT or COUNT() more than 50.000 records. Why not Apex?
Apex uses more resources than a simple API call, such as extra memory, CPU time, etc, so there's additional limits in place. The Developer Console, contrariwise, uses the API, which is just a server-...
17
votes
Accepted
Code Optimization
There are a number of optimizations that could occur here, but none of them are "major." Here goes.
Stop Describing!
This one may or may not be your main culprit, because you're not caching your ...
16
votes
Accepted
Does SOQL query get consumed when querying from an empty set?
Yes, even though the Set<Id> accountIds is empty, 1 SOQL query will be executed and will be counted against the 100 SOQL queries limit.
On a similar note, the code below won't be counted as 1 ...
16
votes
Accepted
How do I bulkify queries for directly or indirectly related records?
It is common to have collections of records to process, especially when considering triggers (though there are many other places where collections of records may require processing together). When ...
Community wiki
13
votes
Accepted
Batch Apex that does DML and multiple callouts
You can combine the callout and the DML in the same method if you want to; the only restriction is that no callouts are allowed after a DML. Each call to start, execute, and finish are separate ...
13
votes
Avoiding Governor limits on test classes
Set up your test data in @testSetup. To avoid using your test governor limits, start with Test.startTest():
@isTest class MyUnitTestClass {
@testSetup static void testSetup() {
Test.startTest();...
13
votes
Accepted
Limitation on external system calling Salesforce
Is there any limit on how many times an external systems can call Salesforce to get data?
Yes, there is an API Limit as how many API calls can any external system make into Salesforce. There's a 24-...
13
votes
Accepted
How to determine Platform Event Size in Apex to ensure to be within < 1 MB
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the ...
12
votes
Any reason to skip DML on empty lists?
When I look at the results of the following coding, I would still use if (!list.isEmpty()) { DML list; }
List<Account> accs = new List<Account>();
System.debug(Limits.getCpuTime()); // 1
//...
12
votes
Accepted
SOQL Performance With LIMIT 1
In the case of assignment to a single record and filtering on an Id, there is zero impact on your governor usage. It won't affect CPU Time, and if you were already enforcing exactly one result by ...
12
votes
Accepted
Determine whether Apex transaction is asynchronous
Yes. The System class offers four methods you can call to determine if you're in Asynchronous Apex and, if so, which type:
isBatch()
Returns true if a batch Apex job invoked the executing code,...
12
votes
Accepted
Does data referenced from the Platform Cache consume heap space?
When the data is loaded to memory the heap size is consumed.
I uploaded a book (around 1.5mb) to my org as an attachment, and then split it into several 100kb or less parts to the org's cache. Turns ...
11
votes
Trigger Error: System.LimitException: Apex CPU time limit exceeded
Try at least restricting to Account records which might match, and mapping by those values.
public with sharing class LeadService
{
public static void findAccountsByDomain(List<Lead> ...
11
votes
Accepted
Is there still a batch size limit in trigger?
Triggers now come in two sizes, batches of 200 and batches of 2,000. The APIs that chunked down to 100 records per trigger chunk are/will be retired in June 2021. For Platform Events, expect triggers ...
11
votes
Accepted
Governor limits in scheduling ScheduledApex jobs - how much and where to find them?
Refer to this link for more info on scheduled jobs: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
1. How many jobs can you schedule at once?
You can ...
11
votes
Accepted
Governor Limits on System.enqueueJob in Asynchronous Apex – Documentation Wrong?
Yes, the documentation in question is incorrect. You can prove that the Limits class does not conform to what is written therein fairly easily:
public class Demo implements Queueable
{
public void ...
10
votes
Accepted
Governor Limit on number of child records fetched
Yes it will because the 50,000 record count in single transaction.
As per Execution Governors and Limits:
In a SOQL query with parent-child relationship subqueries, each
parent-child ...
10
votes
Accepted
Count of SOQL Statements used in Debug logs
It's the Limits class:
Integer queriesUsed = Limits.getQueries();
10
votes
Accepted
Bulkification of SingleEmailMessage
It should instead be:
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
for Opportunity record : records)
{
Messaging.SingleEmailMessage email = ...
10
votes
Dealing with auto-batching of triggers
However, this 1) doesn't work for before insert since the id doesn't yet exist, and 2) feels legitmately hacky. Are there any better ways to do this?
Your approach (Set<Id> recordsProcessed) is ...
10
votes
Accepted
First error: Too many query rows: 50001
While it won't fix your issue, never use the global access modifier unless you know you need it.
Take advantage of the QueryLocator pattern and iterate over your query itself:
Instead of:
global ...
10
votes
Transactional governor limits and managed packages
For certified managed packages, each namespace gets its own set of limits. Excepted from this separation, however, is CPU Time. Packages which are not certified share all per-transaction governors ...
10
votes
Accepted
API Inbound and Callout limits SOAP vs REST
An API call is an inbound request, an API callout is an outbound request.
API calls are rate-limited, limiting clients to the number of calls they are allowed to make daily. One API call costs one API ...
10
votes
Getting error System.AsyncException: Future method cannot be called from a future or batch method: when I am calling future method from a trigger
The error message does a pretty good job of describing the issue here.
You have a trigger on Lead that calls an asynchronous @future method
Your @future method updates your Leads
Which causes your ...
10
votes
Accepted
I'm exceeding 50k query rows with a child query, and no exception. Why does this work?
As explained in Apex Governor Limits:
In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query. These types of queries have a limit of three ...
9
votes
Accepted
System.LimitException: Too many SOQL queries: 101
Hi You are getting the error because you are using Messaging.renderStoredEmailTemplate() in for loop as this is counted towards the SOQL governor limit as one query. To avoid the exception you have to ...
9
votes
System.LimitException: Too many SOQL queries: 101
Rishi Golyan correctly identified the issue, however, Messaging.renderStoredEmailTemplate() works on single ids rather than a list of ids.
So, simply moving that method call to be outside of your ...
9
votes
Accepted
How do processes consume SOQL queries?
It's one DML and SOQL per 200 records or a single DML "chunk."
To illustrate this, consider the following code:
contact[] c = [select id from contact limit 5];
id accountid = [select id from account ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
governorlimits × 881apex × 475
soql × 238
batch × 106
trigger × 101
limits × 92
cpulimit × 51
unit-test × 35
query × 35
visual-workflow × 33
scheduled-apex × 30
email × 28
visualforce × 27
callout × 26
managed-package × 24
process-builder × 23
api × 22
rest-api × 20
future × 19
dml × 18
asynchronous × 18
bulkification × 18
exception × 16
performance × 16
schedulebatch × 15