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

ApexCRUDViolation: check for object-level delete permission does not work #1458

Open
illarionova opened this issue May 7, 2024 · 3 comments
Labels
USER STORY New feature or request

Comments

@illarionova
Copy link

I am trying to check for object-level delete permission on a custom object before performing a DML delete operation on it.

The check is performed as it is shown in documentation here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm.

public with sharing class TestClassApex {
    public static void exampleMethod() {
        List<CBConfig__c> configs = [SELECT Id FROM CBConfig__c WITH SECURITY_ENFORCED];
        if (Schema.SObjectType.CBConfig__c.isDeletable()) {
            delete configs;
        }
    }
}

I'm running the check through:

sf scanner run --format csv --outfile CodeAnalyzerGeneral.csv --target ./ --category Security

And getting ApexCRUDViolation.

I'm using @salesforce/sfdx-scanner@latest-beta version 4.1. I also tried with the version 3.23.

@johnbelosf
Copy link
Collaborator

Thanks for raising @illarionova! That specific rule likely needs to be updated to match current best practices - we are aware there are some gaps between how rules are setup and the latest best practice.

These days we recommend using User Mode for queries and database operations as per our docs

We are currently working on overhauling our core Code Analyzer architecture to make it easier for us to help you understand which rules align with the latest best practice, which will likely lead to us contributing updates to rules in engines such as PMD later in the year / early next year.

@johnbelosf johnbelosf added the USER STORY New feature or request label May 7, 2024
Copy link

git2gus bot commented May 7, 2024

This issue has been linked to a new work item: W-15703310

@rsoesemann
Copy link

Related ticket in the PMD repo pmd/pmd#4997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
USER STORY New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants