I am trying to empty the recycleBin. Thus I need to query the existing SObjects
of the records. If a match of the records SObject
Name has been found, than the query should happen. Else it just shouldn't query anything. The return type is a query.
How should I write the else part without having crashing problems when the SObject
does not exists.
I thought of a try catch block where the try part would contain the
if(exists){query;}
and the catch part would just don't do anything, means it would be empty. Does that make sense? What would you suggest?
Boolean exists = Schema.getGlobalDescribe().containsKey(sObjectName);
try {
if(exists){
return Database.getQueryLocator('SELECT Id FROM ' + sObjectName
+' WHERE isDeleted=true ALL ROWS');
}
}
catch (QueryException ex) {
// do nothing
}