Skip to main content
2 of 2
edited title
identigral
  • 7.8k
  • 34
  • 33
  • 45

PMD check fails: validate CRUD before DML Operation

I have a list of sObjects. In this list I have records of Account,Contact and Opportunity which needs to be updated. so before updating the list I am doing CRUD check on Account , Contact and Opportunity like below:

List<sObject> lstOfSObjects = new List<sObject>();
lstOfSObjects.add(new Account(.......));
...
lstOfSObjects.add(new Contact(.......));
...
lstOfSObjects.add(new Opportunity(.......));
...
if (!Schema.sObjectType.Account.isUpdateable()) {
 return...                   
}
if (!Schema.sObjectType.Contact.isUpdateable()) {
 return...                   
}
if (!Schema.sObjectType.Opportunity.isUpdateable()) {
  return...                
}

update lstOfSObjects;

Even if I am checking CRUD check for every sObject still Apex PMD is throwing an error at the update DML saying : Validate CRUD before DML Operation.

Any help?

sfdc07
  • 634
  • 1
  • 18
  • 36