Tuesday, November 1, 2011

How to set Debug Log for Apex Class and Force.com Site

In sales force it is very easy to log and track the apex program. To log the apex code use below line of code:

        System.debug(“Your message”);
Lets assume you have written below line of code in one of the controller extension’s constructor :
   
    System.debug('\n\nI Am In the constructor of Apex class \n\n');

When you are setting debug for internal Apex execution:

1- Enable the log for particular user who is going to execute that code. Go to “Setup | Administration Setup | Monitoring | Debug Logs“.

2- To enable the log for this user click on new button .

3- Select the user and save.

4- Now execute that Visualforce page for which controller code is written.

5- After execution again go to the Debug Logs page, where the user is added. You will see the screen like below

    As you can see now that new row is added in “Debug Logs” section. click on the “view” button.
    Debug statement printed in debug logs.

When you are setting debug for external Force.com site execution:

Steps 1,2 are same.

3-  Select Site User and save

Steps 4,5 are same

N.B. How to see site user:   App SetUp ->Create ->Site ->Click on Site Lebel ->Click Public Access Settings ->Click View users button.


For more information on log levels, see “Setting Debug Log Filters” in the Salesforce online help.

No comments:

Post a Comment