I am trying to update one of the related objects once the Account merge is completed.
Database.MergeResult results = Database.merge(masterAcct, duplicateAcct, false);
getUpdatedRelatedIds()
method from the MergeResult class is giving me all the related Ids as List<String>
but I want to filter a specific object from the list and update that record. So far I could only think of this way but let me know if there's a better way to do the same.
List<String> returnedIds = new List<String>{'a812f000000CnFqAAK','a262f000000ndRnAAI','0012f00000lnY0rAAE'};
List<Id> usefulIds = new List<Id>();
for (String s : returnedIds)
{
if (String.valueOf(Id.valueOf(s).getSObjectType()) == 'UseFulObject__c'){
usefulIds.add(s);
}
}
List<UseFulObject__c> updateUsefulRecords = new List<UseFulObject__c>();
for (Id s: usefulIds){
UseFulObject__c uo = (UseFulObject__c) s.getSObjectType().newSObject(s);
uo.IsActive__c = false;
updateUsefulRecords.add(uo);
}
update updateUsefulRecords ;