Introduction-
In this blog we will understand the Action Merge from a Plugin (SDK message) perspective.
Problem Statement:
1) We want to retrieve data once the Merge is performed on two records.
2) We want to merge 2 records using a plugin (C# code).
Solution:
For the first statement, We shall be triggering a plugin on the message "Merge".
While using the plugin registration tool, select message as Merge.
Below code is to be used-
if (context.InputParameters.Contains("Target") &&
context.InputParameters.Contains["Target"] is EntityReference)
{
EntityReference Master = (EntityReference) context.InputParameters["Target"];
Guid duplicate = (Guid) context.InputParameters["SubordinateId"];
}
For the second problem statement, we will invoke/ use the Merge method.
Below is the code-
var target = new EntityReference();
target.Id = Recordid; //master record id
target.LogicalName = Entity.EntityLogicalName;
var merge = new MergeRequest();
merge.SubordinateId = Record2id; // record to be merged id
merge.Target = target;
merge.PerformParentingChecks = false;
var updateContent = new Entity();
updateContent.fieldname= "test";
merge.UpdateContent = updateContent;
var merged = (MergeResponse)svc.Execute(merge);
Target- Master recordSubordinate Id- the record to be merged.UpdateContent- additional entity attributes to be set during the merge operation for accounts, contacts, or leads. This property is not applied when merging incidents.Perform Parenting Checks- a value (Yes/ No) that indicates whether to check if the parent information is different for the two entity records.
Comments
Post a Comment