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

Validate PMD check fails: validate CRUD before updating list of sobjects in apexDML Operation

Source Link
sfdc07
  • 634
  • 1
  • 18
  • 36

Validate CRUD before updating list of sobjects in apex

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?