function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shirley MaglioShirley Maglio 

During a merge of two Contact Records, the EventRelation record of the losing record is not getting copied to the winning record.

During a merge, the losing Contact record's TaskRelations (TR) and EventRelations (TR) are not being transfered to the winning Contact record, if the losing Contact record is not the Primary Contact on the Task and Event.

I tried to make the above transfer happen with the following:
1. Retrieve TR and ER with relationId = losing Contact ID
2. Clone the TR and ER retrieved from step 1 and update the clone copy's relationId to point to the winning Contact ID
3. Delete the retrieved TR and ER from step 1.
4. Insert the cloned copy of TR and ER from step 2.

Code snippet for the above four steps:
private static void updateEventRelation(String WinId, String LosingId) 
        {        
            //Check if there are any EventRelations or not - If present then change that to Wininng Party
            List <EventRelation> lstEventRelationForDeletion = new List <EventRelation>();
            List <EventRelation> lstEventRelation = new List <EventRelation>();


            
            //Check if there are any EventRelations or not - If present then change that to Wininng Party
            for(EventRelation objEventRelation : [Select EventId, RelationId FROM EventRelation where RelationId=:LosingId]){
                    lstEventRelationForDeletion.add(objEventRelation);
                    EventRelation e = new EventRelation();
                    e = objEventRelation.clone(false, true, false, false);
                    e.eventid = objEventRelation.eventid;
                    e.relationid = WinId;
                    lstEventRelation.add(e);
                }
       
 
            if(lstEventRelationForDeletion.size() > 0 && lstEventRelationForDeletion <> null){                        
                delete lstEventRelationForDeletion;                 
            }
            
            if(lstEventRelation.size() > 0 && lstEventRelation <> null){
                insert lstEventRelation; 
                system.debug('@@@@@@ inserted ');
            }
        }

When I ran the merge with the above four steps, the TaskRelation got transfered over to the winning Contact record, but the EventRelation did not.
The debug logs shows that the above four steps for EventRelation were executed. I have confirmed via SOQL query that there is a new EventRelation with relationId pointing to the winning Contact record, but this new ER is not showing up on the winning Contact record's activity related list on the screen.

What wold be the possible reasons why the ER is not showing up on the winning Contact record's activity related list, when it works nicely for TR. Any help is appreciated.