Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Do I need apex try catch block separately for each SOQL or the query exception can be handled in one try-catch block?

Asked by Aashish Chaursiya Apr 18, 2023 851 views 1 answer
Share

About this question

I am using one try-catch block inside which there are multiple SOQL queries WITH SECURITY_ENFORCED. Do I need to try catch blocks 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 acc = [SELECT id, Name FROM Account WITH SECURITY_ENFORCED]; List con = [SELECT id, LastName FROM Contact WITH SECURITY_ENFORCED]; //somelogic here }catch(Exception e){ System.debug('Error--'+e.getMessage()); } }

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.