Friday 13 April 2012

Merge and Update Merged Entity record content

In this article , I am creating two account records and merge both record using crm 2011 MergeRequest Class
using (_serviceProxy = new OrganizationServiceProxy(
       // This statement is required to enable early-bound type support.
             .Add(new ProxyTypesBehavior());

       // Create the first account, which will be merged into
       Account account1 = new Account();
       account1.Name = "First Account";
       account1.Description = "Merged Into";
       _account1Id = _serviceProxy.Create(account1);

       // Create the second account, which will be merged from
       Account account2 = new Account();
       account2.Name = "Second Account";
       account2.NumberOfEmployees = 55;

       _account2Id = _serviceProxy.Create(account2);

       // Create the target for the request.
       EntityReference target = new EntityReference();
       target.Id = _account1Id;
       target.LogicalName = Account.EntityLogicalName;

       // Create the request.
       MergeRequest merge = new MergeRequest();
       // SubordinateId is the GUID of the account merging.
       merge.SubordinateId = _account2Id;
       merge.Target = target;
       merge.PerformParentingChecks = false;

      Account updateContent = new Account();
      updateContent.Address1_Line1 = "new street 1";

      // Set the content you want updated on the merged account
      merge.UpdateContent = updateContent;

      // Execute the request.
      MergeResponse merged = (MergeResponse)_serviceProxy.Execute(merge); 


No comments:

Post a Comment