Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the first of several identical warnings in a file clears all subsequent warnings #154

Open
yarhamjohn opened this issue Oct 20, 2023 · 0 comments

Comments

@yarhamjohn
Copy link

yarhamjohn commented Oct 20, 2023

Describe the bug
I have a class with several methods that each do an update on an sObject. All of these update calls are highlighted by the linter with the security-ApexCRUDViolation warning. If I fix the first of these in the file, then all the subsequent updates no longer get highlighted even though they should still be in violation.

If I fix the second in the file but not the first, all the highlights are the second are cleared but the first highlight remains. This doesn't change even if the linting is re-run.

Apex PMD Output
n/a - the linting no longer identifies the violations.

Apex PMD Settings
v0.6.2

  • pmdBinPath: blank
  • rulesets: empty
  • additionalClassPaths: empty

Apex File

public with sharing class CustomOpportunityUtilsController
{
    private final ApexPages.StandardController controller;

    private Opportunity opp;

    public CustomOpportunityUtilsController(ApexPages.StandardController standardController)
    {
        controller = standardController;

        Opportunity standardOpp = (Opportunity) controller.getRecord();

        opp = [SELECT Id, StageName FROM Opportunity WHERE  Id = :standardOpp.Id];
    }

    public PageReference moveCloseDate()
    {
        Date today = Date.today();

        Date firstOfThisMonth = Date.newInstance(today.year(), today.month(), 1);

        if (Opportunity.sObjectType.getDescribe().isUpdateable())
        {
            update new Opportunity(Id = opp.Id, CloseDate = firstOfThisMonth);
        }
        else
        {
            return null;
        }

        return new ApexPages.StandardController(opp).view();
    }

    public PageReference updateName()
    {
        update new Opportunity(Id = opp.Id, Name = 'New Opp Name');

        return new ApexPages.StandardController(opp).view();
    }

    public PageReference closeOpps()
    {
        List<Opportunity> opps = [SELECT Id, StageName FROM Opportunity WHERE StageName = :opp.StageName];
            
        for (Opportunity o : opps)
        {
            o.StageName = 'Closed';
        }

        update opps;
        
        return new ApexPages.StandardController(opp).view();
    }
}

Screenshots
After linter is run, before any fixes are implemented:
image

^^ All the above underlines are: Validate CRUD permission before SOQL/DML operation (rule: Security-ApexCRUDViolation)

After fixing the first update call in the file and rerunning the linter:
image

^^ the first query still has the violation, but now all subsequent queries/updates after the one that was fixed in moveCloseDate() are no longer highlighted despite still being in violation.

Versions (please complete the following information):

  • OS: Windows 11
  • vscode: 1.83.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant