rspec/rules/S5539/apex/rule.adoc

53 lines
1.5 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,apex]
2021-04-28 16:49:39 +02:00
----
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
2021-04-28 16:49:39 +02:00
* 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[]