Debugging patterns for programmers who pull their hair off on “The page submitted is invalid for session” on force.com site..

As a programmer debugging on force.com site pages is always a night mare and the reasons are obvious. We do not get exceptions handled if there is a visual force page error gracefully and the generic site.error message does not show a meaningful message. Makes you think whether salesforce is competing with Microsoft IE on this. But here is one tip which helped me to save time on debugging the crazy error “The page submitted is invalid for session”

This would be a scenario where you were using a command link button to submit a form and i was using an action tag submitting to a controller. I also had a javascript on click and on complete event which was submitting the form.

Buggy code

[apex]
<apex:commandLink action="{!navAction}" onclick="javascript:disabled=true;" onComplete="javascript:disabled=false;NEXTACTION();"
</apex:commandLink>

<apex:actionFunction action="{!navAction}" name="NEXTACTION" />

[/apex]

So the form was giving me the crazy Invalid for session error and I tried so many things to fix this but in vain.
Code fix
[apex]
<apex:commandLink onclick="javascript:disabled=true;" onComplete="javascript:disabled=false;NEXTACTION();"
</apex:commandLink>

<apex:actionFunction action="{!navAction}" name="NEXTACTION" />
//Removed the action tag on the command link.

[/apex]

Here was a simple solution a programmer came up with which solved the problem.

So the solution was
a. removed the action tag on the command link and had the action function call the controller action. So the debugging pattern to learn here is
a. Avoid duplicate calls to the controller action.

So if you get the invalid session error and if you use an action function and a command link or button call to controller, have one call to the controller.
Avoid duplicate method calls to the controller –Duplicate controller action pattern.. I will be writing a series of articles on fixing issues quickly which will save you some hair and Time. Save Time !! Work better..

Leave a Reply

Your email address will not be published. Required fields are marked *

Get free tips on Salesforce
Get free tips on Salesforce
We respect your privacy.