[SalesForce] Code Caching Issue

I have a sites page, and it seems to work fine from a functional perspective. It has a custom controller that retrieves some data from a custom object and the Contact object, displays the data to the user, and lets them submit an updated version of the data into another custom object.

But after a certain amount of time (24-48 hours), when I go to the page I get a 'Not Authorized message'. After much testing, and thinking it was a a problem with css/statis resources, I have now found that the problem seems to be with the controller (i.e. a page with no references to css/static resources still fails)

When I get the error, I can login to SF and simply view the apex controller class in the usual Setup – Develop – Classes interface, and the public sites page then works again for another 24-48 hours.

What am I missing here? I have different versions of the page setup with cache enabled, and with cache set to false – they all fail.

Best Answer

In case anyone ends up here, I did finally work this out with help from this post: http://www.tgerm.com/2010/10/debugging-sites-authorization-required.html

I set up a debug page as described in the post, included it as a sites page, and when the page failed, this debug page finally revealed the error.

My controller class had a test method in it, which in turn was referencing a second class - and that second class was trying to update a field it wasn't allowed to when running as a Sites user. So for reasons that aren't clear to me, the controller work fine for a while, and the test ran fine when logged in, but at some point, it would error out, and I could only fix it by viewing the class while logged in...

I only worked this out by following the link above, and setting up a debug page that I could access as the Sites User, which finally showed me the error - every other debug method provided no information...

Related Topic