Finally, Salesforce brings Debugging feature. I was waiting for this one for a long time and I am quite sure that many other developers like me also waited for this one.

Today in this post, I would like to explain how you can use this feature and make your Salesforce developer life more powerful.

Before I start, I would like to mention that this feature is not available in Developer orgs, it is only available in Sandboxes. You need to contact Salesforce to enable this feature in your Sandboxes. There is cost involved in getting this one enabled. To know about the cost, please contact Salesforce.

With the assumptions that you have enabled this feature in your Sandbox, you need to setup your Sandbox as well as your Eclipse workplace. Below are the steps mentioned in Salesforce guide –

Setup Sandbox for Apex Debugger –

Setup Force.com IDE –

  1. First you need to Install or Update Force.com IDE plugin as instructed below –
  2. Once done, create a Salesforce project as instructed here. Note – Make sure you mark your Eclipse project as work online.

Setup Eclipse Debugger –
This is the most important step where you need to setup your Eclipse Debugger. To do that –

  1. Click on the Debug Icon in the toolbar and select Debug Configuration
  2. Select Remote Apex Debugger
  3. Click on the New Launch Configuration Icon
  4. Give some name of your configuration
  5. Click Browse and select your project
  6. Click Apply, and then Debug.

Once you are done with the above steps, your basis setup is done and you are ready to use Apex Debugger. So let’s use now.

I have created one very basic Apex class to start with. The code is below –

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public with sharing class SudiptaDeb_ApexDebug_Demo {
public void method1(String str){
method2(str);
}

private void method2(String str){
String strToBePassed = 'String from method1: ' + str;
method3(strToBePassed);
}

private void method3(String str){
String strToBeDisplayed = 'Final String: ' + str;
System.Debug(strToBeDisplayed);
}
}

Now let’s follow the below steps to do the debugging –

  • Setup breakpoint @ line # 3, 7 and 12. Intention is that we will see the values of the variables during the execution flow. You can setup breakpoint by double clicking on the line numbers
  • Open the Debug perspective by choosing Window | Open Perspective | Other | Debug
  • Click on the Debug icon and launch the new debug configuration (created earlier) You will get yellow gear icon indicating that your debug session is ready. 
  • Let’s execute the below code from Developer console’s Execute Anonymous Window –         new SudiptaDeb_ApexDebug_Demo().method1(‘Sudipta Deb’);
  • Once you start that you will see that in Eclipse the executing is waiting at your first breakpoint as shown below –
  • Watch the value of the variable as shown below – 
  • Click on Step Over icon you will see the execution is now moved to second breakpoint. Watch for the value now as shown below – 
  • Again click on Step Over icon you will see the execution is now moved to third breakpoint. Watch for the value now as shown below – 
If you are able to do the above steps and see the results, it means you have Apex Debugger setup correctly and you now have the power you need in your hand. 

Great!!! In my next post, I have explained some of the more advanced features of Apex Debugger. Till then, feel free to post your comments and let me know how you feel about this great feature from Salesforce. Have a nice day.