Sample Code to use UpsertRequest in CRM 2015\2016

UpsertRequest was a new request introduced in CRM 2015 Online Update 1.

The request based on the alternate key specified, looks for the record, if the record is existing it updates it else it creates a new record.

https://nishantrana.wordpress.com/2016/10/25/alternate-keys-in-crm-2015crm-2016/

UpsertResponse has a property named RecordCreated which is false if the record is found and updated else it is true if record is created. The Target property holds the reference of the record created or updated.

Suppose we have following record created. It has Alternate key defined on “Alternate Key Field”

Sample Code

As we have demo entity record with alternate key field having value as “My Alternate Key 1” it will update the record.

Running it again this time changing the value for the alternate key field.

It creates a new record.

Hope it helps..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s