Free Salesforce Developers Tutorials >

Chapter 8 - Apex DML and Database Methods >

Lead Conversion | Method in Apex Database Class

Lead Conversion | Method in Apex Database Class

What You’ll Learn

S2 Labs

What Is Lead Conversion In Salesforce?

Lead conversion in Salesforce is a process in which a lead record is converted into Accounts, Contacts & Opportunities. This happens when a lead is identified as a qualified Sales prospect.

Lead Conversion Using Apex Coding

There exists a Database class method “convertLead” which is used to convert the lead but other than this method there are various variables and classes used to convert a lead in Apex which is shown below through a Sample code example.

Lead Conversion:public static void main() {
    Lead l = [SELECT Name FROM Lead WHERE Name like’ sh % ’LIMIT 1];
    Lead l1 = new Lead(LastName = ‘’, CompanyName = ’’);
    insert l1;
    Database.LeadConvert lc = new Database.LeadConvert();
    System.debug(‘ID of record inserted is: ’;
    lc.convertedStatu s = ’Closed Converted’;
    lc.ownerId = [SELECT Id FROM User LIMIT 1].Id; // any user id
    Database.LeadConvertResult lcr = Database.convertLead(lc);

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *