3

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

5

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!

  • Thanks for your comments Can you please share some code snippets on how you use google analytics event to handle global parameters? – buyan kumar May 12 '13 at 18:38
  • sure thing. I have the laptop handy now. – Shane McLaughlin May 12 '13 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. – Shane McLaughlin May 13 '13 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 '14 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. – Shane McLaughlin Apr 6 '14 at 23:38
1

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? – buyan kumar May 13 '13 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.