SUMMARY:
I am currently implementing Merge Cases functionality and need to be able to edit fields on the losing and winning record during this process. Looking at the documentation depending on whether duplicates are kept Update and Delete triggers are fired and the way to identify this as a merge operation is to check the MasterRecordId field on the losing record.
I am unable to access the MasterRecordId during the merge Case process. This is true whether the merge maintains or deletes the duplicate record.
DECLARATIVE APPROACH:
When maintaining the duplicate I attempted to access it via Validation and Workflow rules (since maintaining duplicates only fires the Update Triggers, which is before the field gets populated). But the formula in the Validation field does not recognise the MasterRecordId field nor is it available to select in a workflow rule.
PROGRAMMATIC APPROACH:
I have also attempted setting the merge to delete the losing record as the documentation implies that I would then be able to access the populated MasterRecordId field in the afterTrigger. Similar to the above paragraph that field is not available even through SOQL so I am unable to identify a merge process and make field updates accordingly
public static void afterDelete(Map<Id,Case> oldMap, Map<Id,Case> newMap){
system.debug('This is the after delete function');
for(Case c : oldMap.values()){
system.debug('THE DELETED CASES FROM THE MERGE: ' + c);
}
List<Case> mergedCases = [SELECT MasterRecordId FROM Case WHERE MasterRecordId != null ALL ROWS];
}
The debug in the above snippet does show the case I'm looking for but with the MasterRecordId field available and attempting to save gives us this error:
No such column 'MasterRecordId' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
I have also checked the API version my Salesforce is running it does appear to be a version after MasterRecordID was added (v46).
Any assistance with this would be greatly appreciated.
Sincerely, Andrew