+ Start a Discussion
Rajesh ShahRajesh Shah 

sid problem with JavaScript and VF page

Something very interesting I found today and thought to share it.

We have a custom button on detail page of a object with the OnClick JavaScript behaviour. The JavaScript checks certain field values and based on that, it redirects the User to a Visualforce page. One of the parameters we passed to visualforce page was named 'sid' i.e. we used to pass sid = Id of the record. Everything worked fine except for one case.

When we login to the org and click the button, it didn't redirected us to the VF page. Instead what it did was it toggled between the VF page and the detail page continuously till the browser got tired and threw an error. However if we went to any other Visualforce page and then came back to the detail page and again clicked the button, everything worked fine and we were redirected to the VF page. Weird. 

After a lot of debugging, I finally found the problem. It was the name of the parameter sid. I looked into the details of the page getting called using Firebug and I found that my sid parameter contained the session id instead of the Id of the record. For some reason, the first time when we try to visit the Visualforce page, salesforce replaced the sid with session id. However, after visiting another page and then calling our VF page, the sid now had the Id of the record. 

To solve, we replaced the sid parameter with something else. Lesson learnt: Do not use the standard parameter that salesforce uses unless you are trying to override it.

 


Message Edited by Rajesh Shah on 01-20-2010 04:09 PM
Chirag MehtaChirag Mehta

Interesting ..