Thursday, June 16, 2016

Apex Debugger || All you need to know || Advanced Configuration

This post is in continuation of my previous post where I have explained the basic configuration of Apex Debugger. If you haven't gone through that, I would request you to please go here.

So with the assumption that you have configured Apex Debugger correctly and can do debugging, in this post, I will explain some advanced configurations which you can do with Apex Debugger.

So let's start -
  • Choose for which user you want to enable the Apex Debugger - You can choose the user for which you want to enable the Apex Debugger. For that open Debug Configuration. Then check the Whitelisting Enabled and Use SOQL where clause option. Then put the where clause. For example in the below screenshot, I have put the ID of the user and clicked on the Query button 
  • Choose the request type - With this option you can select the request type for which you want to enable the Apex Debugger. Currently we can enable Apex Debugger for the below options - Execute Anonymous, Inbound Email Service, Invocable Action, Lightning/Aura, Quick Action, REST, Run Tests Synchronous, SOAP, Synchronous, Visualforce, Visualforce Remote Method. If you don't choose anything, it means it is enabled for all the above types of requests.
  • Choose Entry Point - With this option, you can choose the entry point. For example if you want to enable Apex Debugger for particular Visualforce page, you can put .*/apex/DemoPage.apexp
Let's check out the above mentioned advanced configurations with one example.

Use case: Create a VisualForce page where accounts can be selected by lookup button. Once an account is selected, all the associated contacts will be displayed.
Implementation:
Here is the VisualForce Page -

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<apex:page standardController="Contact" extensions="SudiptaDeb_ContactList_Demo" showheader="false">
<apex:form >
 <center>
  <br/><br/>
        <apex:outputLabel value="Account Name"> 
   <apex:inputField value="{!Contact.AccountId}" required="false" id="lid">
    <br/><br/><br/>
           <apex:actionsupport event="onchange" rerender="check"/>
         </apex:inputField>
        </apex:outputLabel>
        <apex:outputPanel id="check">
      <apex:outputLabel value="Contacts:" rendered="{!contact.AccountId!=null}">
           <apex:selectCheckboxes value="{!selectedAccount}">
              <apex:selectOptions value="{!items}"/>
          </apex:selectCheckboxes><br/>
         </apex:outputLabel>
        </apex:outputPanel>
 </center>
</apex:form>
</apex:page>
Here is the controller SudiptaDeb_ContactList_Demo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
public with sharing class SudiptaDeb_ContactList_Demo {
 public contact selectedAccount{get;set;}
  public SudiptaDeb_ContactList_Demo(ApexPages.StandardController stdCtrl) {
  selectedAccount=(Contact)stdCtrl.getRecord();
  }
  public List<SelectOption> getItems(){
       List<Contact> cntList=[select Name from Contact
              where AccountId=:selectedAccount.AccountID];
       List<SelectOption> options = new List<SelectOption>();
        for (Contact c:cntList){
   options.add(new SelectOption(c.Name,c.Name));
        }
        return options;
 }
 }

Debugging:
Now what I will do here are mentioned below -
  • I will give my User ID in the Debug Configuration | Whitelisting Enabled section to make sure only my requests will be considered for Apex Debugging. With this option, if someone else is working in the same Sandbox, their requests will not be tracked here.
  • I will select VisualForce under request type because I am only interested to debug when the execution will trigger from VisualForce page. My intention is that I will do some activity in the VisualForce page and I would like to debug the Apex controller code.
Here is the screenshot of all the configurations -

Now in the controller, I will put breakpoints @ line # 4, 7 and 13. After that with Debugger session on, when I will select an account in the VF page, the execution will stop at the breakpoints. Below is the screenshot -

So now I can debug my controller by starting the execution from VisualForce page. With this example, I believe you will feel more comfortable to play with other supported request types. Go ahead. It's all yours. 

Lastly I would like to inform you about few limits and considerations.
Apex Debugger Limits -

Apex Debugger Considerations -
Click here

Please let me know your feedback. Thanks in advance. Happy Salesforce Debugging!!!
Location: Waterloo, ON, Canada

0 comments:

Post a Comment