Prevent double posting!
Recently in a project we ran into a problem where a customer wanted to post a form to Salesforce.It worked like a charm until we got reports from the customer that duplicate data came into the system.Yes we had run into the double posting problem.Of course the first thing you do is to Google. The solutions on the internets was alot of Javascript, not the way we roll ;).We started out by trying to lock the viewstate[] sadly the viewstate and the setting of it is not synchrounous so setting it and the check if it is set on the second post just resulted i futile attempts. The solution we then headed for was to use an external queue to check if the form was already posted.
We implemented it really simple.
1) Set up a Guid for your form. Guid.NewGuid();
2. On post, we check if the guid exist in the table, if not add the guid to the table and return false else return true. We do this by encapsulating the lookups in transactions because - and this is the key - by using SQL Server transactions, we effectively get the lock we require but out-of-process.
3) Now the form will never again double post.
If you are interested in the sourcecode just mail and we will send you the sourcecode.
/PP
Comments