1

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());
}
}

1 Answer 1

6

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .