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


2 Answers 2


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}']);
       'Page Errors', 
       '{!$Site.OriginalUrl}--{!$Site.ErrorDescription} experienced by {!$User.id}']);                      

Best of luck!

  • Thanks for your comments Can you please share some code snippets on how you use google analytics event to handle global parameters? May 12, 2013 at 18:38
  • sure thing. I have the laptop handy now. May 12, 2013 at 19:39
  • If you haven't been in GA for a month or so, they've added events to the real-time section so you can see errors as they happen (or don't) which is great for fix validation. May 13, 2013 at 2:15
  • cool. I'm currently trying this, but one question pops into my mind. How does Analytics work for HTTPS and HTTP version of teh Force.com Site? We've 2 URLS for Force.com Site, and only one place where we can enter Tracking Code. But Google Analytics Dashboard only creates profile for URL based approach. So I can either create a Website Profile for HTTPS or HTTP version, will the api track both versions automatically?
    – VarunC
    Apr 5, 2014 at 12:36
  • Varun, we run it on both. The ga script has irks as https, which can run on non- secure site with no issues. Apr 6, 2014 at 23:38

Take a look at this link for some ideas about debugging sites pages - helped me in the past

  • @Shane McLaughlin Thanks for sharing the script. I have a weird issue where one visual force page throws a run time error when we use language as spanish and it works for english. We are using custom labels and it just throws a generic exception. Have you faced any issues like this? May 13, 2013 at 2:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .