[SalesForce] Debugging force.com site visual force pages

We have a force.com site where we have a lot of visual force pages which are under authenticated force.com site license. The issue is that we are getting errors which i assume are runtime where the force.com sites does not show any useful information to debug. I have created debug logs with the logged in user id and guest user profile. When i see the debug log, it shows me the debug log for the page but it shows debug log maximum file size exceeded. Is there a better way to handle run time exception on force.com site pages where we can atleast see stacktrace of errors instead of
Error: Error occurred while loading a Visualforce page.

Please email us if you need to get in touch.
How do you guys handle runtime exceptions and log them currently on force.com sites?
Thanks
Buyan

Best Answer

Try one or more of the following:

Set the debug level to be less verbose (dev console). You'll get major errors back rather than each loop iteration showing up.

There are visualforce global parameters for page and exception. I placed these in a google analytics event on the page so I can see what's being thrown.

Wrap the whole page in a try/catch block, and do a system.debug(logginglevel.error, e) in the last catch. <==assuming you name all your exceptions e like I do). If the log verbosity is the main problem, combine this with #1.

If the error happens after the page loads, like on a save or other action, you could do #3 but use an apex message option to show the error that you're catching on the page (avoid the logs entirely).

Here's the GA script we use (prerequisite is that you have the GA async tag already on the page AND you have your GA id on the salesforce site config page).

<script type="text/javascript">
    var _gaq = _gaq || [];              
    _gaq.push(['_setAccount', '{!$Site.AnalyticsTrackingCode}']);
    _gaq.push([
       '_trackEvent', 
       'Page Errors', 
       '{!$Site.ErrorMessage}', 
       '{!$Site.OriginalUrl}--{!$Site.ErrorDescription} experienced by {!$User.id}']);                      
 </script>

Best of luck!

Related Topic