[SalesForce] Issue with Request time Limit governor exception on force.com sites

We are currently working on a UAT phase for a force.com site implementation where we have custom visual force forms running upto 70 steps. We are currently facing request time governor limit exceeded on our sandbox which has a maximum of 30 minutes allocated. We have a logged an issue with salesforce on this to increase it as we expect 200,000 users to use the site and our forms would run through 70 steps taking atleast 30 to 45 minutes to complete one application per user. Have you faced this request time governor limit in your current or past force.com site implementations and can you share best practices to control it? Can you guys provide insight on how salesforce calculates this request time of 30 minutes for a 24 hour rolling window? Is this session based, request based or page scope? Any help would be appreciated..

Best Answer

Salesforce.com calculates the total amount of time it takes to process the page, including querying the database and rendering the page. Using JavaScript remoting will drastically reduce the time spent rendering the page server-side by offloading this responsibility to the client. Furthermore, using static resources instead of inline JavaScript will also reduce the calculated usage time, because data fetched from a cache (such as the CDN) doesn't count against your total server time. Consider designing your page to use the following code:

<apex:page controller="MySiteController">
    <apex:includeScript value="{!$Resource.mySiteJS}"/>
    <div id="content"></div>
</apex:page>

Your controller can be completely written as remote actions. Note that I have zero view state and only one expression to evaluate. Here's some possible code that you might use in your controller:

public with sharing class MySiteController {
    @RemoteAction
    public static SomeData getSomeData(SomeParam param) {
        // Do stuff here, return SomeData.
    }
    // More remote action functions here
}

The client-side rendering is taken care of inside MySiteJS:

(function() {
    function init() {
        // when the page loads
    }
    // Other functions here. We can also use jQuery, etc...
    addEventListener('load', init, true);
}());

Using this design structure, you should be able to get your Visualforce page loads down to about 20ms, and your remoting actions should typically return in far less than 1000ms even if you have a ton of data you're throwing down the wire. And remember, CDN (your JavaScript) is free of charge, so leverage that fact to reduce your total page time. If you're providing localization strings, I would store the languages in various static resources as well; have the page load the appropriate language pack based on the user's settings.

Related Topic