You need to sign in to do that
Don't have an account?

How to Escape from Query Exception??
How to escape the exception if there are no results from Soql Query and do I hit any Governer Limits by looking at the code??
global class DeleteoldCases{
Public void DeleteoldCases(){
List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC LIMIT 9000];
If (QueryCases == null){return;}
system.debug('********List of Cases********'+QueryCases);
try{
delete QueryCases;
}catch(DmlException e) {
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
}
}
global class DeleteoldCases{
Public void DeleteoldCases(){
List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC LIMIT 9000];
If (QueryCases == null){return;}
system.debug('********List of Cases********'+QueryCases);
try{
delete QueryCases;
}catch(DmlException e) {
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
}
}
your code and query looks good and will not hit any limit, i have just added not empty check.
Please let me know if this helps you
Best Regards,
-Vivek
All Answers
your code and query looks good and will not hit any limit, i have just added not empty check.
Please let me know if this helps you
Best Regards,
-Vivek
If criteria will not met then query will retunr 0 rows hence I have added empty check
Best Regards,
-Vivek