Upsert in MSCRM

If we want to update a record in any entity, we should require GUID. If we know the GUID, we can do it easily, if not, we should retrieve the GUID of that record first, then we can update the record. Here, two database calls (Retrieve and Update) we are making which impacts performance of an application.


In these scenarios, Upsert will be very useful. Upsert request will check in database whether record exists in database, if exists it will update the record or else it will create the record.






So, how do we know that whether Upsert create or update record in each call?


This information we can get from UpsertResponse which contains a Boolean property RecordCreated. If RecordCreated contains “true” it indicates Upsert created the record else updated the record.


Sample Code:

               Entity testEntity = new Entity("new_test");
                testEntity["new_test1"] = "test1";
                testEntity["new_test2"] = "test2";
                testEntity["new_test3"] = "test3";

                UpsertRequest request = new UpsertRequest()
                {
                    Target = testEntity
                };
                try
                {
                    UpsertResponse response = (UpsertResponse)_serviceProxy.Execute(request);
                }
                catch (Exception ex)
                {
                  }


Note: For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises).




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

No comments:

Post a Comment

Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...