
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Batch Apex jobs should execute as fast as possible because other jobs wait in the queue. They will execute faster when their ``++start++`` method returns a QueryLocator object or an iterable which does not use subqueries to include related records. It is more efficient to execute these subqueries separately inside the ``++execute++`` method of the Batch class.
|
|
|
|
|
|
This rule raises an issue when, in the context of a Batch class' ``++start++`` method, the ``++Database.getQueryLocator(query)++`` method is called with a query containing one or more subqueries
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,apex]
|
|
----
|
|
global class MyBatch implements Database.Batchable<sObject> {
|
|
global MyBatch(){
|
|
}
|
|
|
|
global Database.QueryLocator start(Database.BatchableContext BC){
|
|
return Database.getQueryLocator([SELECT Id, (SELECT id FROM Contacts) FROM Account]); // Noncompliant
|
|
}
|
|
|
|
global void execute(Database.BatchableContext BC, List<sObject> scope){
|
|
// ...
|
|
}
|
|
|
|
global void finish(Database.BatchableContext BC){
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm[Using Batch Apex] (See the "Batch Apex Best Practices" section)
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Execute subqueries in the "execute" method
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The SOQL query
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|