-
Salesforce Trigger to convert leads into accounts and contacts and add task to it
Salesforce Trigger to convert leads into accounts and contacts and add task to it
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
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());}
}
}
Log In to reply.
Popular Salesforce Blogs

Tips to Choose Reliable Salesforce Consulting Partners in 2019
Salesforce now helps enterprises to streamline various facets of a business ranging from sales to product delivery and customer support. Salesforce is so popular for…

What is Enhanced Domain Security in Salesforce in 2023?
What is Enhanced Domain? Enhanced domains are the latest version of My Domain that meets the latest browser requirements. With enhanced domains, all URLs across your…
Popular Salesforce Videos
Features of Salesforce Industries (Vlocity)
There are many features of Salesforce Industries that make it a one-stop solution for businesses. Salesforce Industries or Vlocity offers Omnichannel processes with lightning Web,…
How Much Time to Give to Salesforce Preparation?
Wondering how much time to give for Salesforce preparation? Watch this video it explains distinctly how much time you need to learn. If you have…
Spring '21 Release - Time-dependent Action in Salesforce Flows
If you’re familiar with scheduled actions in Process Builder or time-dependent actions in workflow rules, know that scheduled paths on record-triggered flows can accomplish the…