[SalesForce] Has anyone had issues with initial page load times when injecting a second VF page via AJAX

I have a few visualforce pages that, together, make up a custom dashboard. The first page or "shell" page is just a HTML form that lets you select a client services rep and an optional client type selector. Clicking submit calls an AJAX load call (via jquery) to inject the second page body contents – which is a VF page with a list of accounts and some embedded data (in sub-queries).

The very first time you load the page, it can take up to 20-30 seconds…after that it takes about 2-3 seconds. This is regardless of which client rep I select and the number of accounts or amount of embedded sub-query data.

None of the pages use an apex:form (to eliminate viewstate tax). The issue arises only sporadically and only the first time a person loads the page.

When I used the Dev Console it shows a huge block of time where the DB transaction holds the page for like 19 seconds.

I'm wondering if anyone has seen a case where there is some delay or deferred processing because of the way the page is being called and injected. I can't for the life of me figure out what would cause such a huge delay on a query – it contains a number of sub-queries but I have a third page (predicated on this page) that loads even more data with more conditions and is never a problem. Given that the third page works fine I'm wondering if its an authentication or caching issue…but if that was the case, why would the Timeline blame the DB call (unless it's mistakenly identifying the hold up)? Stumped.

Best Answer

Since no one has posted an answer I'll have a go.

As you suggest, the problem probably isn't the injection of the second page, but the DB call.

There are a number of things you can do to reduce time in the DB such as the obvious narrowing your query, and adding indexes by way of making any fields involved in WHERE clauses indexed by using the "External Id" checkbox in the field configs.

About a year ago, we've also added the ability to add custom indexes by contacting support. Custom indexes can be turned on in fields that didn't previously support indexing (even formula fields). Custom indexes even support a composite index of up to 2 fields.

There was a great blog post about this back in February that you might want to read about. http://blogs.developerforce.com/engineering/2013/02/force-com-soql-best-practices-nulls-and-formula-fields.html

Related Topic