function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jburns12jburns12 

Help with test Code

trigger Base_TR_ConvertLead on Lead (after insert, after update)
{
//create a string of ids to be converted
String records = '';
//get all records with status Lead Status= Qualified
for(Lead lead : Trigger.New)
{
if(lead.Status == 'Qualified')
{
if(records == '')
    records = lead.Id;
else
    records = records + ',' + lead.Id;
    }
}
//call the single click lead convert method to convert the lead
if(records != '')
{
MassConvert.MassLeadConvert.ConvertRecords(records, true, true, '','',true, 'Auto Convert');
}
}

 

I need help writing the test code for this trigger, I am new to Apex and not very sure of myself. Can some one give me a test example?

 

mikefitzmikefitz

The only thing you need to do is create two leads, one "Qualified" and one not "Qualified" and then assert that the leads went through.

//Create a qualified lead
Lead lead01 = new Lead();
         lead01.status = "Qualified";
insert lead01;


//Create a Open Lead
Lead lead02 = new Lead();
         lead02.status = "Open";
insert lead02;

 

 

 

 

Pradeep_NavatarPradeep_Navatar

Try out this sample code of testclass given below :

 

            static testMethod void testrunmethod()

                {                             

                Lead lead = new Lead();

                lead.status = "Qualified";

                insert lead;

                }

            static testMethod void testrunmethod()

                {

                Lead lead1 = new Leas();

                lead1.status = "Open";

                insert lead1;

                }

 

Hope this helps.