You need to sign in to do that
Don't have an account?
roni shore
Create record in custom object upon account merge
I have a custom object custom_obj__c, where i have to create records upon account merge activity. I am writing the following trigger to acheive
issue is that the Master_Account__c on custom object is MD relation on Accout and whenever I am trying to merge ..getting this error
"Apex trigger AccountMergeTrigger caused an unexpected exception, contact your administrator: AccountMergeTrigger: execution of AfterDelete caused by: System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []: Trigger.AccountMergeTrigger: line 9, column 1"
trigger AccountMergeTrigger on Account (after delete) {
List<Account_Backup__c> listAccountBackup = new List<Account_Backup__c>();
for(Account acct : trigger.old) {
if(String.isNotBlank(acct.MasterRecordId)) {
listAccountBackup.add(new Account_Backup__c(Name = acct.Name, Master_Account__c = acct.id));
}
}
if(listAccountBackup.size() > 0) {
insert listAccountBackup;
}
}
Please suggest
issue is that the Master_Account__c on custom object is MD relation on Accout and whenever I am trying to merge ..getting this error
"Apex trigger AccountMergeTrigger caused an unexpected exception, contact your administrator: AccountMergeTrigger: execution of AfterDelete caused by: System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []: Trigger.AccountMergeTrigger: line 9, column 1"
trigger AccountMergeTrigger on Account (after delete) {
List<Account_Backup__c> listAccountBackup = new List<Account_Backup__c>();
for(Account acct : trigger.old) {
if(String.isNotBlank(acct.MasterRecordId)) {
listAccountBackup.add(new Account_Backup__c(Name = acct.Name, Master_Account__c = acct.id));
}
}
if(listAccountBackup.size() > 0) {
insert listAccountBackup;
}
}
Please suggest
By design Master-Details relationship works that way, you cannot have Child records exist while you delete Master record in Master-Detail relationship model. You can try changing relationship from MD to Lookup so that you can have your Child records exist even after your Lookup records is deleted or try creating some stage object to store your Account information and create that record without having any relationship with Accont object. This Link has detailed explanation on MD and Lookup: http://sfdcsrini.blogspot.com/2015/10/difference-between-master-detail.html
Thank you
All Answers
By design Master-Details relationship works that way, you cannot have Child records exist while you delete Master record in Master-Detail relationship model. You can try changing relationship from MD to Lookup so that you can have your Child records exist even after your Lookup records is deleted or try creating some stage object to store your Account information and create that record without having any relationship with Accont object. This Link has detailed explanation on MD and Lookup: http://sfdcsrini.blogspot.com/2015/10/difference-between-master-detail.html
Thank you
In order to display your child records linked to your Parent Lookup Object, you have to link them first and pull your related list on to the page layout!
Thank you