function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Geetha ReddyGeetha Reddy 

very urgent issue.....

HI,

I am trying to convert a lead to Account , Opportunity , Contact .
But i am getting Error as :


ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00QK0000002q7ZnMAI; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [] 

 

trigger LeadConvert on Lead (after insert)
{
for(Lead myLead: Trigger.new)
{
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
}

Avi646Avi646

Well it seems like you are trying to convert a already Converted lead. Put a check like this

for(Lead myLead: Trigger.new){
    if(myLead.isConverted==true){

    //your code here
    }
}

 

Geetha ReddyGeetha Reddy

Thank u 

 

i updated my trigger as

trigger LeadConvert on Lead (after insert)
{
for(Lead myLead: Trigger.new)
{
if (myLead.isconverted==false){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());

}
}
}

 

but i am facing same problem .

Edwin VijayEdwin Vijay

I guess, the problem is with the below line of code

 

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

 

But since you are not updating the row, i'm still not sure how you got it.. But, can you make a workaround for dat statement?