0

I am using one try-catch block inside which there are multiple SOQL queries WITH SECURITY_ENFORCED. Do I need try catch block separately for each SOQL or the query exception would be handled in that one try-catch block which I am using.

Sample Code:

Apex

public static void myMethod(some parameter){
try{
//do I need separate try-catch block to catch the Query exception or it will be caught by the catch I am using??
 List<Account> acc = [SELECT id, Name FROM Account WITH SECURITY_ENFORCED];
 List<Contact> con = [SELECT id, LastName FROM Contact WITH SECURITY_ENFORCED];
//somelogic here
}catch(Exception e){
System.debug('Error--'+e.getMessage());
}
}
6

One is enough, unless you want to act differently depending on which query caused the exception.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.