if(dupObjDel !=null && dupObjDel.size() > 0 ) {
if(isSafeObjectDel( dupObjDel ) ) {
delete dupObjDel; // ERROR in this line
}
}
public static boolean isSafeObjectDel(List<sobject> delId) {
boolean result=false;
Sobject del =delId[0];
String objName= del.id.getSObjectType().getDescribe().getName();
return isDeletable(objName);
}
public static Boolean isDeletable(String sObjectType)
{
SObjectType schemaType = Schema.getGlobalDescribe().get(sObjectType);
return (schemaType.getDescribe().isAccessible() && schemaType.getDescribe().isDeletable() && schemaType.getDescribe().isMergeable());
}
ERROR Object: dupobjdel in file: /classes/CustomMerge.cls
Send this code to checkmarks. Error:
CRUD Delete error from security review.
isDeletable()
method. ThegetSObjectType()
method of theList
class can fetch the type, and then you can callgetDescribe()
on that directly (which is faster thangetGlobalDescribe()
). Store the result in a variable, and then you'll be able to callisAccessible()
,isDeletable()
, etc... a bit more efficiently too. The only situation I can think of where this wouldn't be safe is if you tried to do this on aList<SObject>
that contained more than one type ofSObject
.