You need to sign in to do that
Don't have an account?
vishal yadav 86
Trigger to convert lead
I want to write a trigger to convert lead after updating the status field to "working-contacted".
Review the errors on this page.
VishalYadav.LeadTrigger: execution of AfterUpdate caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, convertedStatus is required.: [Status] Trigger.VishalYadav.LeadTrigger: line 8, column 1
TRIGGER:
----------
Trigger LeadTrigger on Lead (after update) {
For(Lead l: Trigger.new)
{
if(l.IsConverted == false)
{
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(l.id);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
} }
}
Review the errors on this page.
VishalYadav.LeadTrigger: execution of AfterUpdate caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, convertedStatus is required.: [Status] Trigger.VishalYadav.LeadTrigger: line 8, column 1
TRIGGER:
----------
Trigger LeadTrigger on Lead (after update) {
For(Lead l: Trigger.new)
{
if(l.IsConverted == false)
{
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(l.id);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
} }
}
It need some more work on trigger part to acihive it optimized way Look at below code
Some time back I was working on one similar requirement below post helped me built very optimized solution.
https://blog.deadlypenguin.com/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
https://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/
Hope it help.
Arvind_Singh.