You need to sign in to do that
Don't have an account?
Edward East
Automatically convert Lead to Account if Status has changed to "signed".
I have just created a formassembly form which we sent to potential clients. Those potential clients are Leads and a lot of their information is in the database already. Once they have completed the form and returned it to us the Lead status automatically changes from "Identified" to "Signed". At that point I ould like to set up a trigger that immediately converts those leads into a Person - Account. Anyone knows how I can achieve this?
Please try below code and make sure you have all required field populated for Account and Contact if any (Maybe through "Map Lead Fields" section ).
trigger ConvertToAccountOnStatusSigned on Lead (after insert,after update) {
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
List<Database.LeadConvert> lcList = new List<Database.LeadConvert>();
for (Lead lead : Trigger.new) {
if (lead.isConverted == false && lead.Status=='Signed') {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
String oppName = lead.Name;
//if set true, no opportunity will be created
lc.setDoNotCreateOpportunity(True);
lc.setConvertedStatus(convertStatus.MasterLabel);
lcList.add(lc);
}
}
if (lcList.size() > 0 ){
List<Database.LeadConvertResult> lcrList = Database.convertLead(lcList,false);
}
}
Regards,
Dipak NIkam
All Answers
Please check below, this can be of your help.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_convertLead.htm?SearchType=Stem&Highlight=lead%7Cleading%7CLead%7Cleads%7CLeads%7C%7Cconvert%7Cconverting%7Cconverts%7Cconverted%7CConverting%7CConvert%7CConverts
Regards,
Dipak Nikam
trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) {
if (lead.isConverted == false)
{
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
String oppName = lead.Name;
lc.setDoNotCreateOpportunity(True);
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());
}
}
}
Please try below code and make sure you have all required field populated for Account and Contact if any (Maybe through "Map Lead Fields" section ).
trigger ConvertToAccountOnStatusSigned on Lead (after insert,after update) {
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
List<Database.LeadConvert> lcList = new List<Database.LeadConvert>();
for (Lead lead : Trigger.new) {
if (lead.isConverted == false && lead.Status=='Signed') {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
String oppName = lead.Name;
//if set true, no opportunity will be created
lc.setDoNotCreateOpportunity(True);
lc.setConvertedStatus(convertStatus.MasterLabel);
lcList.add(lc);
}
}
if (lcList.size() > 0 ){
List<Database.LeadConvertResult> lcrList = Database.convertLead(lcList,false);
}
}
Regards,
Dipak NIkam