In high transaction CRM system, it is often possible that two users are working on same record and updating record at the same time. This might result in data loss. For example, you opened a contact record and trying to update Mobile number for that contact. At the same time, another user opened record and trying to update Last Name. Suppose they both clicked the save button at almost same time. What will happen? The update request which reaches later will be the end result of data. So the first update request will get lost.
To avoid these kind of scenarios Microsoft introduced Optimistic Concurrency with CRM 2015 Online Update 1. This feature is not yet available for CRM on premise.
How to enable Concurrency Behavior for Entities:
Concurrency version is enabled by default for all custom entities. For Out of the box entities, you can use IsOptimisticConcurrencyEnabled method to check if an entity is supporting this behavior.
How to use Concurrency Behavior Programatically:
As of now the only way to enable concurrency is by SDK call. There is no way to configure Concurrency Behavior through UI. Below is the sample code to enable concurrency behavior:
// Retrieve a contact record using Retrieve method
var contact = _serviceProxy.Retrieve("contact", contactid, new ColumnSet("firstname","lastname"));
//Determine the retrieved row version of contact
Console.WriteLine("After Retrieveing Row Version of Contact:" + contact.RowVersion);
if (contact != null)
// Create an Entity object
Entity newContact = new Entity()
LogicalName = contact.LogicalName,
Id = contact.Id,
RowVersion = contact.RowVersion
// Update the Contact income.
newContact["new_income"] = new Money(1000000);
// Set the concurrency behavior to check for a row version match. If row version does not match
//It will throw exception otherwise contact record will gets updated.
UpdateRequest contactReq = new UpdateRequest()
Target = newContact,
ConcurrencyBehavior = ConcurrencyBehavior.IfRowVersionMatches
// Perform the update operation.
UpdateResponse accountUpdateResponse = (UpdateResponse) _serviceProxy.Execute(contactReq);
If we walk through the above code, we retrieved the contact record. After retrieving the contact record, we retrieved the RowVersion property of the retrieved contact record. Then, we created a new Contact object to update the income of the contact. While creating that new object, set the RowVersion property equals to RowVersion of retrieved contact. If you notice highlighted line in the code, we are setting Concurrency Behavior as IfRowVersionMatches.
When this request reaches to server, it checks for RowVersion property of Update Request and current RowVersion property of the record. If the RowVersion matches, it will update the record else an exception will be thrown and update request will not be performed.