function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BritishBoyinDCBritishBoyinDC 

Strange Cache Problem

I have a sites page, and it seems to work fine. It has a custom controller that retrieves some data from a custom object and the Contact object, displays the info to the user, and lets them submit an updated version to 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 age 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?

Best Answer chosen by Admin (Salesforce Developers) 
BritishBoyinDCBritishBoyinDC

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, included it as a sites page, and when the page failed, this debug page finally revealed the error.

 

My controller class has a test method in it, which in turn was referencing a second class - and that 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, 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...

All Answers

Devendra@SFDCDevendra@SFDC

Hi,

 

Have you added cache and expires attribute in <apex:page> tag?

 

cache : A Boolean value that specifies whether the browser should cache this page. If set to true, the browser caches the page. If not specified, this value defaults to false. For Force.com Sites pages, if this attribute is not specified, this value defaults to true.

 

expires: The expiration period for the cache attribute in seconds. If the cache attribute is set to true, but this attribute is not specified, this value defaults to zero. For Force.com Sites pages, if cache is not set to false, this value defaults to 600 seconds.

 

Thanks,

Devendra

BritishBoyinDCBritishBoyinDC

I have - there is a version of the page setup with caching, and one without - no difference. They both suffer from same issue...

BritishBoyinDCBritishBoyinDC

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, included it as a sites page, and when the page failed, this debug page finally revealed the error.

 

My controller class has a test method in it, which in turn was referencing a second class - and that 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, 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...

This was selected as the best answer