Skip to content

[apex] Mark Database DML statements in For Loop #1713

@JorneVL

Description

@JorneVL

Affects PMD Version:
6.12

Rule:
AvoidDmlStatementsInLoops

Description:
The current check only warns for the insert word.
But this doesn't warn you when using the Database functions ( see sample 1 ).
This does the exact same thing.

Maybe we can add a rule that check for DML in a method name ( sample 2 ).
But this is something that is personal and can be a false notification.
If we add a rule then they can choose this for their own.

Code Sample demonstrating the issue:
Sample 1

public class Something {
    public void foo() {  
        for (Integer i = 0; i < 151; i++) {
            Account account;
            // ...
            Database.insert(account);
        }
    }
}

Sample 1

public class Something {
    public void foo() {  
        for (Integer i = 0; i < 151; i++) {
            Account account;
            // ...
            account.insertWithContact();
        }
    }
}

Running PMD through: Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions