From de000a033c95b92e9b629a02e8a711f221075af8 Mon Sep 17 00:00:00 2001 From: Jonathan Wiesel Date: Thu, 13 May 2021 19:13:59 +0200 Subject: [PATCH 1/3] Update docs for OperationWithLimitsInLoop --- .../resources/category/apex/performance.xml | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pmd-apex/src/main/resources/category/apex/performance.xml b/pmd-apex/src/main/resources/category/apex/performance.xml index 0ed0f78e73..431ac73a28 100644 --- a/pmd-apex/src/main/resources/category/apex/performance.xml +++ b/pmd-apex/src/main/resources/category/apex/performance.xml @@ -99,7 +99,7 @@ public class Something { class="net.sourceforge.pmd.lang.apex.rule.performance.OperationWithLimitsInLoopRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#operationwithlimitsinloop"> - Database class methods, DML operations, SOQL queries, or SOSL queries within loops can cause governor limit exceptions. Instead, try to batch up the data into a list and invoke the operation once on that list of data outside the loop. + Database class methods, DML operations, SOQL queries, SOSL queries, Approval class methods, Email sending, async scheduling or queueing within loops can cause governor limit exceptions. Instead, try to batch up the data into a list and invoke the operation once on that list of data outside the loop. 3 @@ -130,6 +130,32 @@ public class Something { List> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead]; } } + + public void messageInsideOfLoop() { + for (Integer i = 0; i < 10; i++) { + Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); + Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email}); + } + } + + public void approvalInsideOfLoop(Account[] accs) { + for (Integer i = 0; i < 10; i++) { + Account acc = accs[i]; + Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); + req.setObjectId(acc.Id); + Approval.process(req); + Approval.lock(acc); + Approval.unlock(acc); + } + } + + public void asyncInsideOfLoop() { + for (Integer i = 0; i < 10; i++) { + System.enqueueJob(new MyQueueable()); + System.schedule('x', '0 0 0 1 1 ?', new MySchedule()); + System.scheduleBatch(new MyBatch(), 'x', 1); + } + } } ]]> From d92c7ffb56e518bfeaf94097485b9feeefc0a6a0 Mon Sep 17 00:00:00 2001 From: Jonathan Wiesel Date: Thu, 13 May 2021 19:23:34 +0200 Subject: [PATCH 2/3] Update docs for ApexCRUDViolation --- pmd-apex/src/main/resources/category/apex/security.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pmd-apex/src/main/resources/category/apex/security.xml b/pmd-apex/src/main/resources/category/apex/security.xml index 43df3b038f..de42b89592 100644 --- a/pmd-apex/src/main/resources/category/apex/security.xml +++ b/pmd-apex/src/main/resources/category/apex/security.xml @@ -53,7 +53,9 @@ should be [suppressed](pmd_userdocs_suppressing_warnings.html). Date: Fri, 18 Jun 2021 14:59:14 +0200 Subject: [PATCH 3/3] [doc] Update release notes (#3276) --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index a2b26c2bc0..8afce58a7a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -54,5 +54,7 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions +* [#3276](https://github.com/pmd/pmd/pull/3276): \[apex] Update ApexCRUDViolation and OperationWithLimitsInLoop docs - [Jonathan Wiesel](https://github.com/jonathanwiesel) + {% endtocmaker %}