You need to sign in to do that
Don't have an account?
LAMCORP
Lead convert creating duplicate records
Dear all,
I am hoping some can solve this puzzle. It is testing my patience. I have a lead convert trigger on convert. The trigger is supposed to create 2 custom object records but it is creating duplicates of each record so that is 4 records!!!
trigger LeadConvert on Lead (after update) {
for(Lead lead:System.Trigger.new) {
if (Trigger.new.size() == 1) {
if (Trigger.new[0].ConvertedAccountId != null) {
Account a = [Select a.Id, a.Name, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
a.Description = Trigger.new[0].Name;
update a;
// insert a Sales Monitor Line
Line_del__c obj = new Line_del__c();
obj.Name = a.Name;
obj.Team_s_Dept_s_del__c = lead.Sales_Team__c;
obj.ME1__c = lead.Sales_ME1__c;
obj.ME2__c = lead.Sales_ME2__c;
obj.DTR3__c = lead.Sales_DTR__c;
obj.CU__c = lead.Sales_CU__c;
obj.Linked_Account__c = a.Id;
insert obj;
// insert a CR Monitor Line
Line_del__c obj2 = new Line_del__c();
obj2.Name = a.Name;
obj2.Team_s_Dept_s_del__c = 'a0PV0000000F8Kr';
obj2.ME1__c = lead.CR_ME1__c;
obj2.ME2__c = lead.CR_ME2__c;
obj2.DTR3__c = lead.CR_DTR__c;
obj2.CU__c = lead.CR_CU__c;
obj2.Linked_Account__c = a.Id;
insert obj2;
}
}
}
}
It seems like some workflow is making the trigger run again, please check your workflows, try de-activating and check the trigger.
All Answers
Have you tried without the for loop? Can you tell if there is trigger on account to do any update on lead?
Hi,
Thanks for the reply. I have tried your code and deactivated my trigger. There is no other trigger on the Account.
Very puzzling. Any other ideas?
As it is in my Sandbox, I have deactived all triggers except the one you sent over. Still creating duplicate items.
very puzzling indeed, could you copy/paste the debug log for a lead you convert.
I have butting my head against the wall for a while on this one. Appreciate the help.
Do I have to have a unit test for the debug log to show?
Just convert any lead, make sure it creates a new account in the process
A little longer than I thought. 6 parts not 2 :)
yep, the trigger runs twice, can you change the trigger to before and see if it still happens?
It seems like some workflow is making the trigger run again, please check your workflows, try de-activating and check the trigger.
Neat detective work!! I deactivated all Lead workflows and now only create 2 records as it should. The only issue is the workflows are needed!!! I will have to do process of elimination and try to figure out a workaround. Thanks again.