Unable to use Convert lead () Method using Trigger
Hi Team,
I am receiving below error :
FATAL_ERROR|System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_STATUS, invalid convertedStatus: Qualified: []
I am not sure as this trigger is compiled successfully .I want to create Opportunity as well so I commented out "lc.setDoNotCreateOpportunity(false); " this statement .
No worries Sanj (I have resolve it by using statement if (lead.isConverted == false) //to prevent recursion) And BTW thanks for looking into my issue ,
I am now able to convert lead using Convert lead() Method . I am posting my trigger just in case if some body need this :
trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) { if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id);
No worries Sanj (I have resolve it by using statement if (lead.isConverted == false) //to prevent recursion) And BTW thanks for looking into my issue ,
I am now able to convert lead using Convert lead() Method . I am posting my trigger just in case if some body need this :
trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) { if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id);
Is it possible to attach an exicting account like standard lead conversion process,here it will create the new account and contact for that one.....I don't want like this i want to add to an exciting account.
No worries Sanj (I have resolve it by using statement if (lead.isConverted == false) //to prevent recursion) And BTW thanks for looking into my issue ,
I am now able to convert lead using Convert lead() Method . I am posting my trigger just in case if some body need this :
trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
String oppName = lead.Name;
lc.setOpportunityName(oppName);
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());
}
}
}
Regards,
All Answers
Hi Mayank,
Please follow the below step and your trigger will work as expected.
1. Create a Picklist value as "Qualified" in the field Lead Status of Lead Object and check the field converted to True
Mark it as resolved, if it helps you.
Sanj
No worries Sanj (I have resolve it by using statement if (lead.isConverted == false) //to prevent recursion) And BTW thanks for looking into my issue ,
I am now able to convert lead using Convert lead() Method . I am posting my trigger just in case if some body need this :
trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
String oppName = lead.Name;
lc.setOpportunityName(oppName);
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());
}
}
}
Regards,
Hello Joshi,
Is it possible to attach an exicting account like standard lead conversion process,here it will create the new account and contact for that one.....I don't want like this i want to add to an exciting account.