apex – How to remove a PMD rule for SOQL CRUD Operation for Setup Objects?
In the ApexCRUDViolation document from PMD it is written that:
Since Winter ‘23 (API Version 56) you can enforce user mode for database operations by using WITH USER_MODE in SOQL. This makes Apex to respect Field-level security (FLS) and object permissions of the running user. When using user mode, no violation is reported by this rule.
Thus if you run any query with WITH USER_MODE then it should remove the violation by default.
Something like this.
Here I used a query on Account and you can see a violation.
But if I add USER_MODE then the violation gets ignored.
Or even with WITH SECURITY_ENFORCED, I dont see any violation.
Read more here: Source link



