Skip to main content
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) ...
Brent Bowers's user avatar
  • 3,162
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 ...
Daniel Ballinger's user avatar
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-...
sfdcfox's user avatar
  • 500k
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 ...
sfdcfox's user avatar
  • 500k
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 ...
smukov's user avatar
  • 5,613
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 ...
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 ...
sfdcfox's user avatar
  • 500k
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();...
sfdcfox's user avatar
  • 500k
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-...
Jayant Das's user avatar
  • 30.6k
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 ...
salesforce-sas's user avatar
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 //...
loeachim's user avatar
  • 463
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 ...
Adrian Larson's user avatar
  • 151k
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,...
David Reed's user avatar
  • 93.4k
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 ...
Renato Oliveira's user avatar
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> ...
Adrian Larson's user avatar
  • 151k
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 ...
sfdcfox's user avatar
  • 500k
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 ...
Bob Lopez's user avatar
  • 1,481
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
Tushar Sharma's user avatar
10 votes
Accepted

Count of SOQL Statements used in Debug logs

It's the Limits class: Integer queriesUsed = Limits.getQueries();
Adrian Larson's user avatar
  • 151k
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 = ...
Adrian Larson's user avatar
  • 151k
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
sfdcfox's user avatar
  • 500k
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 ...
Derek F's user avatar
  • 63.2k
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 ...
sfdcfox's user avatar
  • 500k
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 ...
Rishi Golyan's user avatar
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 ...
Derek F's user avatar
  • 63.2k
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 ...
sfdcfox's user avatar
  • 500k

Only top scored, non community-wiki answers of a minimum length are eligible