You are currently viewing Salesforce Developer Interview Questions Part5

Salesforce Developer Interview Questions Part5

Salesforce Developer Interview Questions – Apex debugging and Exception handling

APEX- Debugging and Exception handling

54. What is debugging and How do you debug apex ?

Answer:

Debugging can be defined as the process of finding the root cause of a problem or a bug in a code and fixing it.

Salesforce provides debug logs to debug apex . We can also access debug logs from the developer console.


55. Can you explain the steps to debug the code in apex?

Answer:

Step 1 : Enable the debug logs . To enable the debug logs goto setup → Quick find Debug logs →

Click New “Select the users for which you want to enable debug logs”

Enter “Start Date”

Enter “Expiration Date”

Enter “Debug Level “

Step 2 : Run the functionality for which you want to debug .

Step 3 : Go back to the debug logs from setup and Open the debug logs for that particular user.

Step 4 : Analyze the debug logs to find the issue.


56. What does the debug log file contain or What information does the debug log provide?

Answer:

Debug log provides the information about the following.

  • Database changes
  • HTTP callouts
  • Apex errors
  • Resources used by Apex

Automated workflow processes, such as:

  • Workflow rules
  • Assignment rules
  • Approval processes
  • Validation rules
  • Process builder
  • FLOWS

Note : The debug log does not include information from actions triggered by time-based workflows.


57. Why do we use system.debug()?

Answer:

  • System.debug is used to print information of a specific line of code in apex or triggers.
  • Apart from the general debug information, debug logs contains the information from system.debug statements.

Ex: If we want to see if a particular list or set is updated with right values after the logic is processed then we write system.debug to see that list

System.debug(‘accList ⇒’ + accList);


58. What is an exception and what happens when an exception occurs?

Answer:

Exception is an error or event that disrupts the normal flow of code execution. When an exception occurs , code execution halts.


59. What are exception statements?

Answer:

There are two exception statements:

  • Throw statements : Used to generate exception
  • Try, catch, and finally : Used to gracefully recover from an exception.

60. Name a few built-in exception types?

Answer:

  • DMLExcption
  • ListExcption
  • NullPointerException
  • QueryException
  • SObjectException

61. Provide an example of handling generic exceptions as well as specific exceptions using built-in exception types?

Answer:


62. Can you write sample code for a custom exception?

Answer:


63. Can we handle governors limit exceptions using try catch ?

Answer:

  • NO.
  • When we encounter governor limits, code executions halts immediately and this cannot be handled using exception handling .

Leave a Reply