You need to sign in to do that
Don't have an account?
Developement
Merge Duplicate Records
Hello,
Can anyone help to write a logic to merge duplicate records of Custom Object?
Thanks,
Shruti
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hello,
Can anyone help to write a logic to merge duplicate records of Custom Object?
Thanks,
Shruti
Use the merge statement to achieve this functionality.
Find the sample code below:
List<CustomObject__c> ls = new List<CustomObject__c>{new CustomObject__c(name='Sample Name 123'), new CustomObject__c(name='Sample Name 456')};
insert ls;
CustomObject__c masterObj = [SELECT Id, Name FROM CustomObject__c WHERE Name = 'Sample Name 123' LIMIT 1];
CustomObject__c mergeObj = [SELECT Id, Name FROM CustomObject__c WHERE Name = 'Sample Name 456' LIMIT 1];
merge masterObj mergeObj;
The above code will merge the mergeObj to the masterObj record.
Regards,
Arun.
@Dev - I guess you would have to replicate the standard merge would have worked. The general logic to flow would be:
1. Check if master record has no value for a specified column then overwrite value from merged record
2. Reparent all children to master record
3. Delete merge records.
This can be made dynamic by using Schema describe and getting fields for the specific object and doing a one-to-one compare for the above logic.