-
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

All You Need to Know About Salesforce Meetings
Every organization has a Sales department that wishes to have separate functionalities for speedy interactions with potential customers. Instead of making plans for meetings for…

Custom Metadata Test Class Coverage in Salesforce
When we want to implement custom Logic with IF/ELSE cases then in many scenarios we use Custom Metadata Types. But when we try to cover…

8 Best Salesforce Features For Sales Managers 2022
Salesforce Sales Cloud has the greatest customer base of any Sales CRM in the world. Salesforce has solidified CRM for high-performance sales companies by focusing…
Popular Salesforce Videos
Gantt Charts in Salesforce Lightning | Salesforce Tutorials
In this video, you will learn to implement the Gantt Chart in your Salesforce org. We will use Google Gantt Chart scripts and we will…
How to Manage Bulk Data in Salesforce?
Data is at the heart of everything you do in your business. It is also the engine that drives your Salesforce instance. Without it, how…
Schedule Apex Jobs with Lighting Web Components | Developer Quick Takes
Lightning Web Components gives you the ability to give your users a great user experience when interacting with Salesforce. In this example, we will take…