You need to sign in to do that
Don't have an account?
Daniel Gage
LeadConvert trigger is getting a Duplicate_Value error when set up as "after insert"
Help: First exception on row 1; first error: DUPLICATE_VALUE, duplicate value found:This is pretty much driving me crazy tonight. I have a Trigger that converts leads to Contacts based on criteria in another entity.
Below is the Lead Convert, which is failing with
LeadConvertVerified: execution of AfterInsert
caused by: System.DmlException: ConvertLead failed. First exception on row 1; first error: DUPLICATE_VALUE, duplicate value found: []
Trigger.LeadConvertVerified: line 30, column 1
The only thing is... I hve another trigger that is happening on "before insert". But it is working fine. The failure is happening during the conversion process. I have tried changing this to After Update.. but then it never runs, because nothing is updating it. (even though the Before Insert completes successfuly.)
If I change the below to "After Update" it will work when I manually update the lead. But I need it to convert during the bulk upload.
I have no idea what is happening and have spent too much time banging my head against the wall.
1. I am only loading 5 records as a test.
2. I have verified that the leads do not contain duplicate data for Organization__c or Company(Account).
4. There is no duplicate e-mail, etc...
5. Contacts with the same e-mails as the leads do not exist.
Any help would be appreciated.
trigger LeadConvertVerified on Lead (after Insert) {
LeadStatus convertStatus = [
select MasterLabel
from LeadStatus
where IsConverted = true
limit 1
];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for (Lead lead: Trigger.new) {
if (!lead.isConverted && lead.Verified__c == True){
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
lc.setAccountId(lead.Organization__c);
lc.setDoNotCreateOpportunity(TRUE);
lc.setConvertedStatus(convertStatus.MasterLabel);
leadConverts.add(lc);
}
}
if (!leadConverts.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}
}
Below is the Lead Convert, which is failing with
LeadConvertVerified: execution of AfterInsert
caused by: System.DmlException: ConvertLead failed. First exception on row 1; first error: DUPLICATE_VALUE, duplicate value found: []
Trigger.LeadConvertVerified: line 30, column 1
The only thing is... I hve another trigger that is happening on "before insert". But it is working fine. The failure is happening during the conversion process. I have tried changing this to After Update.. but then it never runs, because nothing is updating it. (even though the Before Insert completes successfuly.)
If I change the below to "After Update" it will work when I manually update the lead. But I need it to convert during the bulk upload.
I have no idea what is happening and have spent too much time banging my head against the wall.
1. I am only loading 5 records as a test.
2. I have verified that the leads do not contain duplicate data for Organization__c or Company(Account).
4. There is no duplicate e-mail, etc...
5. Contacts with the same e-mails as the leads do not exist.
Any help would be appreciated.
trigger LeadConvertVerified on Lead (after Insert) {
LeadStatus convertStatus = [
select MasterLabel
from LeadStatus
where IsConverted = true
limit 1
];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for (Lead lead: Trigger.new) {
if (!lead.isConverted && lead.Verified__c == True){
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
lc.setAccountId(lead.Organization__c);
lc.setDoNotCreateOpportunity(TRUE);
lc.setConvertedStatus(convertStatus.MasterLabel);
leadConverts.add(lc);
}
}
if (!leadConverts.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}
}
All Answers