You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[apex] ApexCRUDViolation: False positive with Lists of Objects with getSObjectType().getDescribe() #3877
Description:
I'm getting the "Validate CRUD permission before SOQL/DML operation" error when updating a list of a custom object, but not on the individual.
Code Sample demonstrating the issue:
publicstaticCustomObject__cupdateCustomObject(CustomObject__ccustomObject) {
if (CustomObject__c.getSObjectType().getDescribe().isUpdateable() == false) {
thrownewDmlException('No permissions to update.');
}
// This is fine with no PMD ErrorupdateresultObject;
returnresultObject;
}
publicstaticList<CustomObject__c> updateCustomObjects(List<CustomObject__c> customObjects) {
if (CustomObject__c.getSObjectType().getDescribe().isUpdateable() == false) {
thrownewDmlException('No permissions to update.');
}
// Getting PMD Error: Validate CRUD permission before SOQL/DML operationupdateresultObjects;
returnresultObjects;
}
Expected outcome:
PMD reports a violation at line ..., but that's wrong. That's a false positive.
Since I've checked the object is Updateable, shouldn't that apply to individuals and lists
I'm interested in contributing to this issue, so before I start working it, would you mind sparing your time explaining what the fix will be like and pointing me to some resources to get started.
changed the title [-][apex] ApexCRUDViolation on Lists of Objects[/-][+][apex] ApexCRUDViolation: False positive with Lists of Objects[/+]on Jun 11, 2026
changed the title [-][apex] ApexCRUDViolation: False positive with Lists of Objects[/-][+][apex] ApexCRUDViolation: False positive with Lists of Objects with getSObjectType().getDescribe()[/+]on Jun 11, 2026
Activity
sreenath-tm commentedon Sep 4, 2022
I'm interested in contributing to this issue, so before I start working it, would you mind sparing your time explaining what the fix will be like and pointing me to some resources to get started.
adangel commentedon Sep 5, 2022
Hi @sreenath-tm,
here are a few pointers to get you started:
The specific rule is implemented here: https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java
The test cases are in an xml file: https://github.com/pmd/pmd/blob/master/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml
For understanding the test framework, see https://pmd.github.io/latest/pmd_userdocs_extending_testing.html
The first step would be to add a test case to reproduce the issue. And then dig into the code of the rule to figure out, what's the problem.
lfalcantar commentedon Sep 29, 2022
@sreenath-tm are you still working on this, otherwise I will like to take it.
sternlexa commentedon Nov 1, 2022
I have exactly the same problem with custom objects. Has anyone found a solution?
adangel commentedon Nov 3, 2022
I had a look at the problem and I can't directly reproduce it... without a SOQL expression, the rule is not triggered at all.
So, my sample code looks like this:
With that, it works.
Note, the difference in accessing the SObjectType:
vs.
Are these two equivalent? If yes, then the problem is, that the rule doesn't support the getter, it only supports the property
SObjectType...SurinderjitBajwa commentedon Sep 11, 2023
CWS_AzureAccessToken__c existingToken = [Select ID, Name, CWS_Access_Token__c, CWS_Expire_At__c From CWS_AzureAccessToken__c WITH SECURITY_ENFORCED Limit 1];

DateTime currentDateTime = DateTime.now();
if(existingToken != null){
if(Schema.SObjectType.CWS_AzureAccessToken__c.IsUpdateable() == true
&& Schema.SObjectType.CWS_AzureAccessToken__c.fields.CWS_Access_Token__c.IsUpdateable() == true
&& Schema.SObjectType.CWS_AzureAccessToken__c.fields.CWS_Expire_At__c.IsUpdateable() == true ){
existingToken.CWS_Access_Token__c = newAccessToken;
existingToken.CWS_Expire_At__c = currentDateTime.addSeconds(3000);
Update existingToken;
// Still getting PMD error on this line.
}else{
throwDMLException();
}
}
AngeloChispa commentedon May 12, 2026
Hi, is anyone still working on this ?, if not, i would like to take it.
[-][apex] ApexCRUDViolation on Lists of Objects[/-][+][apex] ApexCRUDViolation: False positive with Lists of Objects[/+][-][apex] ApexCRUDViolation: False positive with Lists of Objects[/-][+][apex] ApexCRUDViolation: False positive with Lists of Objects with getSObjectType().getDescribe()[/+][doc] Update release notes (#3877, #6769)
[apex] Fix #3877: ApexCRUDViolation false positive on Lists of Object…
[apex] Fix pmd#3877: ApexCRUDViolation false positive on Lists of Obj…