+ Start a Discussion
Dorian Kane 5Dorian Kane 5 

hello i need a uni test to pass the auto convert lead to deploy

This is the apex clas i need to deploy 

I dont know muth about apex code and i need help deploy

  1. Public class AutoConvertLeads
  2. {
  3.     @InvocableMethod
  4.     public static void LeadAssign(List<Id> LeadIds)
  5.     {
  6.             Database.LeadConvert Leadconvert = new Database.LeadConvert();
  7.             Leadconvert.setLeadId(LeadIds[0]);
  8.             LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
  9.             Leadconvert.setConvertedStatus(Leads.MasterLabel);
  10.             Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
  11.             Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
  12.             System.assert(Leadconverts.isSuccess());
  13.    }
  14. }
Best Answer chosen by Dorian Kane 5
Deepak GulianDeepak Gulian
@isTest
private class AutoConvertLeadsTest {
    
    @isTest static void convertLeadTestMethod() {
        
        Lead ld = new Lead();
        ld.FirstName = 'First_Test_Name';
        ld.LastName = 'Last_Test_Name';
        ld.Company = 'Fake_Company';
        ld.Email = 'fake_email_today@dfake.com';
        ld.Phone = '1000000001';
        ld.LeadSource = 'Email';
        ld.Status = 'New';

       [Include other required data below before inserting a lead]

        insert ld;
        
        Test.startTest();
                 AutoConvertLeads.LeadAssign(new List<Id>{ld.Id});
                 System.assert(true, ld.IsConverted);
        Test.stopTest();
    }

}

 

All Answers

Dorian Kane 5Dorian Kane 5

Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Leadconvert.setConvertedStatus(Leads.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Leadconvert.setConvertedStatus(Leads.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}

 
Deepak GulianDeepak Gulian
@isTest
private class AutoConvertLeadsTest {
    
    @isTest static void convertLeadTestMethod() {
        
        Lead ld = new Lead();
        ld.FirstName = 'First_Test_Name';
        ld.LastName = 'Last_Test_Name';
        ld.Company = 'Fake_Company';
        ld.Email = 'fake_email_today@dfake.com';
        ld.Phone = '1000000001';
        ld.LeadSource = 'Email';
        ld.Status = 'New';

       [Include other required data below before inserting a lead]

        insert ld;
        
        Test.startTest();
                 AutoConvertLeads.LeadAssign(new List<Id>{ld.Id});
                 System.assert(true, ld.IsConverted);
        Test.stopTest();
    }

}

 
This was selected as the best answer