{"id":2499,"date":"2011-11-26T22:07:09","date_gmt":"2011-11-26T16:37:09","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2499"},"modified":"2015-11-08T03:02:03","modified_gmt":"2015-11-08T03:02:03","slug":"getting-started-with-apex-debug-logs-in-salesforce","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/getting-started-with-apex-debug-logs-in-salesforce\/","title":{"rendered":"Getting started with Apex debug logs in salesforce"},"content":{"rendered":"<p style=\"text-align: justify;\">For the newbie and intermediate developers, most of the time it becomes very necessary to log the\u00a0program\u00a0at some stage \/ line and look into those that what actually is happening with the code.<\/p>\n<p style=\"text-align: justify;\">In salesforce it is very easy to log and track the apex program. To log the apex code use below line of code:<\/p>\n<blockquote><p>System.debug(&#8220;Your message&#8221;);<br \/>\nor<br \/>\nSystem.debug(Logginglevel,&#8221;Your Message&#8221;);<\/p><\/blockquote>\n<p>Log levels available in Apex are (listed from lowest to highest) :<\/p>\n<ul>\n<li>ERROR<\/li>\n<li>WARN<\/li>\n<li>INFO<\/li>\n<li>DEBUG<\/li>\n<li>FINE<\/li>\n<li>FINER<\/li>\n<li>FINEST<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><!--more-->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.<br \/>\nIn 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.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nSystem.debug('msg');\r\nSystem.debug(Logginglevel.INFO,'MsgTxt');\r\n<\/pre>\n<p style=\"text-align: justify;\">For more information on log levels, see &#8220;Setting Debug Log Filters&#8221;\u009d in the Salesforce online help.<\/p>\n<p style=\"text-align: justify;\">Lets assume you have written below line of code in one of the controller extension&#8217;s constructor :<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nSystem.debug('*** In the constructor of extension class ***');\r\n<\/pre>\n<p>First step is to enable the log for particular user who is going to (reason to) execute that code. Go to &#8220;<strong>Setup | Administration Setup | Monitoring | Debug Logs<\/strong>&#8220;.<\/p>\n<figure id=\"attachment_2514\" aria-describedby=\"caption-attachment-2514\" style=\"width: 227px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/Debug-Logs-in-Monitoring-section-of-Administration-setup-salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2514\" title=\"Debug Logs in Monitoring section of Administration setup - salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/Debug-Logs-in-Monitoring-section-of-Administration-setup-salesforce.png?resize=227%2C436&#038;ssl=1\" alt=\"Debug Logs in Monitoring section of Administration setup - salesforce\" width=\"227\" height=\"436\" \/><\/a><figcaption id=\"caption-attachment-2514\" class=\"wp-caption-text\">Debug Logs in Monitoring section of Administration setup &#8211; salesforce<\/figcaption><\/figure>\n<p>To enable the log for this user click on new button as shown in below image.<\/p>\n<figure id=\"attachment_2510\" aria-describedby=\"caption-attachment-2510\" style=\"width: 438px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/List-of-Users-for-Debug-log-enabled-Salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2510\" title=\"List of Users for Debug log enabled Salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/List-of-Users-for-Debug-log-enabled-Salesforce.png?resize=438%2C183&#038;ssl=1\" alt=\"List of Users for Debug log enabled Salesforce\" width=\"438\" height=\"183\" \/><\/a><figcaption id=\"caption-attachment-2510\" class=\"wp-caption-text\">List of Users for Debug log enabled Salesforce<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">on next screen select the user and save the operation.<\/p>\n<p style=\"text-align: justify;\">Now execute that visualforce page on which the code is written.<\/p>\n<p style=\"text-align: justify;\">After execution again go to the Debug Logs page, where the user is added. You will see the screen like below<\/p>\n<figure id=\"attachment_2511\" aria-describedby=\"caption-attachment-2511\" style=\"width: 471px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/View-Debug-logs-in-Salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2511 \" title=\"View Debug logs in Salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/View-Debug-logs-in-Salesforce.png?resize=471%2C198&#038;ssl=1\" alt=\"View Debug logs in Salesforce\" width=\"471\" height=\"198\" \/><\/a><figcaption id=\"caption-attachment-2511\" class=\"wp-caption-text\">View Debug logs in Salesforce<\/figcaption><\/figure>\n<p>As you can see now that new row is added in &#8220;Debug Logs&#8221; section. click on the &#8220;view&#8221; button.<\/p>\n<figure id=\"attachment_2512\" aria-describedby=\"caption-attachment-2512\" style=\"width: 488px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/Debug-statement-printed-in-debug-logs.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2512 \" title=\"Debug statement printed in debug logs\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/Debug-statement-printed-in-debug-logs.png?resize=488%2C90&#038;ssl=1\" alt=\"Debug statement printed in debug logs\" width=\"488\" height=\"90\" \/><\/a><figcaption id=\"caption-attachment-2512\" class=\"wp-caption-text\">Debug statement printed in debug logs<\/figcaption><\/figure>\n<p>And the log is printed as shown above.<\/p>\n<p><strong>Difference between Debug log and System log in Salesforce<\/strong><\/p>\n<p style=\"text-align: justify;\">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,\u00a0anonymous\u00a0apex execution etc however the debug log contains all the debug statements and program execution related to the user for which the debug is granted.<\/p>\n<p style=\"text-align: justify;\">For any query or suggestions, please leave the comments. your feedback is very important.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to debug logs in salesforce with step by step procedure and screenshot, Difference between Debug log and System log in Salesforce<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[337,73,331,336],"class_list":["post-2499","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-apex","tag-debugging","tag-salesforce","tag-visualforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4597,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/advance-apex-debugging-in-salesforce-and-best-practices-videos\/","url_meta":{"origin":2499,"position":0},"title":"Advance Apex debugging in Salesforce and best practices &#8211; Videos","author":"Jitendra","date":"June 27, 2015","format":false,"excerpt":"How to resolve apex debug log size limit issue, Difference between Eclipse and developer console, Interactive Apex Debugging, Keyboard shortcuts for Developer console and Other best practices","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Advance Apex debugging","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Advance-Apex-debugging.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Advance-Apex-debugging.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Advance-Apex-debugging.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Advance-Apex-debugging.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3192,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/how-to-debug-manage-package-in-salesforce\/","url_meta":{"origin":2499,"position":1},"title":"How to Debug Manage Package in Salesforce","author":"Jitendra","date":"February 6, 2013","format":false,"excerpt":"Many times as a developer we need to debug the manage package for possible run time error. For example , while uploading contacts using Import wizard we get \"Internal Server Error\"\u009d and when we try to look into debug log there is no clear indications. However in my experience i\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Debug Manage Package in Salesforce Using Developer Console","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":5515,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/batch-apex-first-error-apex-cpu-time-limit-exceeded\/","url_meta":{"origin":2499,"position":2},"title":"Batch Apex &#8211; First error: Apex CPU time limit exceeded","author":"Jitendra","date":"June 1, 2016","format":false,"excerpt":"Lessons learned while fixing error in Batch Apex , First error: Apex CPU time limit exceeded","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3042,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-12\/","url_meta":{"origin":2499,"position":3},"title":"Salesforce Interview Question &#8211; Part 12","author":"Jitendra","date":"September 13, 2012","format":false,"excerpt":"111 : How to get the Recordtype Id using Dynamic Apex? Ans: Normally to get the RecordtypeId for any sObject we use SOQL and it will count against your limit. So below method will bypass the need of SOQL Query. [java] Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ; Schema.SObjectType s =\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5602,"url":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/tips-to-effectively-use-google-chrome-developer-tool\/","url_meta":{"origin":2499,"position":4},"title":"Tips to effectively use Google chrome developer tool","author":"Jitendra","date":"July 29, 2016","format":false,"excerpt":"While building Lightning Components in Salesforce, how to effectively use Google chrome developer tools to troubleshoot and analyze issue","rel":"","context":"In &quot;Web Technology&quot;","block_context":{"text":"Web Technology","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/"},"img":{"alt_text":"Chrome Dev tools","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/07\/Chrome-Dev-tools.png?fit=600%2C400&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/07\/Chrome-Dev-tools.png?fit=600%2C400&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/07\/Chrome-Dev-tools.png?fit=600%2C400&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":5562,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/summer-16-top-features\/","url_meta":{"origin":2499,"position":5},"title":"Salesforce Summer 16 &#8211; My favorite top 20 features","author":"Jitendra","date":"June 28, 2016","format":false,"excerpt":"List of Salesforce Summer 16 features","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"User Switcher in Salesforce Summer 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/06\/User-Switcher-in-Salesforce-Summer-16.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2499"}],"version-history":[{"count":4,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2499\/revisions"}],"predecessor-version":[{"id":5009,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2499\/revisions\/5009"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}