For the newbie and intermediate developers, most of the time it becomes very necessary to log the program at some stage / line and look into those that what actually is happening with the code.
In salesforce it is very easy to log and track the apex program. To log the apex code use below line of code:
Log levels available in Apex are (listed from lowest to highest) :
Log levels are cumulative. For example, if the lowest level, ERROR, is specified, only debug methods with the log level of ERROR are logged. If the next level, WARN, is specified, the debug log contains debug methods specified as either ERROR or WARN.
In the following example, the string MsgTxt is not written to the debug log because the log level is ERROR, and the debug method has a level of INFO.
For more information on log levels, see “Setting Debug Log Filters” in the Salesforce online help.
Lets assume you have written below line of code in one of the controller extension’s constructor :
System.debug('*** In the constructor of extension class ***');
First step is to enable the log for particular user who is going to (reason to) execute that code. Go to “Setup | Administration Setup | Monitoring | Debug Logs“.
To enable the log for this user click on new button as shown in below image.
on next screen select the user and save the operation.
Now execute that visualforce page on which the code is written.
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.
And the log is printed as shown above.
Difference between Debug log and System log in Salesforce
Normally the debug log gets confused with the System log. Difference in both log is that , the System log contains all the system related information, anonymous apex execution etc however the debug log contains all the debug statements and program execution related to the user for which the debug is granted.
For any query or suggestions, please leave the comments. your feedback is very important.