Hey, i didn't get you.. Let me tell step by step:
What i want is to update parentid of some inactive contacts to one of active contacts. For which, i retrieved inactive contacts and accessed the address records corresponding to each inactive contact and simply updating its parent id.. Let me show you the code snippet:
public void GetAddresses(IOrganizationService service, EntityCollection response, string conString, Guid goldenCustomerID)
{
DataCollection<Entity> addresses = null;
if (response.Entities != null && response.Entities.Count > 0)
{
foreach (var item in response.Entities)
{
QueryExpression query = new QueryExpression { EntityName = "customeraddress", ColumnSet = new ColumnSet("customeraddressid", "parentid", "line1") };
query.Criteria.AddCondition("parentid", ConditionOperator.Equal, item.Attributes["contactid"]);
query.Criteria.AddCondition("line1", ConditionOperator.NotNull);
addresses = service.RetrieveMultiple(query).Entities;
if (addresses != null && addresses.Count > 0)
{
// BulkUpdate(service, addresses, goldenCustomerID, attributeName);
foreach(var addr in addresses)
{
addr.Attributes["parentid"] = new EntityReference("contact", goldenCustomerID);
try
{
UpdateRequest reqUpdate = new UpdateRequest();
reqUpdate.Target = addr;
reqUpdate["SuppressDuplicateDetection"] = true; // Duplicate detection is activated.
// Update the address record.
UpdateResponse updateResponse = (UpdateResponse)service.Execute(reqUpdate); // Error: Duplicate record found for Entity 1071 with ID: "someID "
}
catch (FaultException<OrganizationServiceFault> ex)
{
Console.WriteLine(ex.Message);
}