+ Start a Discussion
tesitesi 

Visualforce Page and Built-in Concurrency?

With standard pages concurrent editing of the same record are detected and responded with following message: "The record you were editing was modified by <user> during your edit session." This is not true for Visualforce page or web service API request (this makes sense):

 

How do you solve this situation when concurrency is required? Of course, we can leverage standard patterns like versioning...but this would require validation rules/workflow rules or triggers for each object we leverage in Visualforce...I cannot believe there is no standard way, isn't it?

 

Example how to simulate this:

1. Standard Pages

User A loads one record, like https://na12.salesforce.com/001U0000003MZzI

User B loads the same record in standard page like https://na12.salesforce.com/001U0000003MZzI

User A changes the record and saves.

User B changes as well and tries to save: "The record you were editing was modified by User A during your edit session." CORRECT!

 

2. Standard Page -> VF Page

User A loads one record in standard page like https://na12.salesforce.com/001U0000003MZzI

User B loads the same record in a VF page like  https://na12.salesforce.com/apex/TransactionTest?id=001U0000003MZzI

User A changes the record and saves.

User B changes the record as well and saves. Record get's saved without any error message! WRONG!



Any ideas appreciated...

 

Best regards,

ritika@developerforceritika@developerforce

Hi,

 

You could probably try something like locking the record. Not sure if you'd be able to do anything in the standard pages, but in controller, you can lock a record while querying for it.

 

Check this out, it may help -

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm

 

 

sfdcfoxsfdcfox

The FOR UPDATE locking statement only works during a single transaction. Each page load is a single transaction. Therefore, it wouldn't work. Best thing I could think of would be to load LastModifiedBy/SystemModStamp, then before saving the record, reload the record and compare the values from when the page was constructed.