You need to sign in to do that
Don't have an account?
rahul Shukla 37
Lead conversion forTest class
public class cfg_LeadUtility {
@InvocableMethod(label='Convert the Lead' description='Convert the lead by LeadId and returns True/False as success/failures' category='Lead')
public static List<String> ConvertLead(List<ID> leadIds) {
List<String> convertedLeads= new List<String>();
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
for (String leadId: leadIds) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadId);
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr ;
try{
lcr = Database.convertLead(lc);
system.debug('*****lcr.isSuccess()'+lcr.isSuccess());
convertedLeads.add(LeadId);
}
catch(exception ex){
system.debug('***LEAD NOT CONVERTED**');
}
}
return convertedLeads;
}
}
i wants to test this class as per below Test class but not covering the code please anyone help me to find the issue in Test class
@isTest
private class cfg_LeadUtilityTest {
static testMethod void testLeadConv() {
//Lead objLead = new Lead( FirstName = 'Test', LastName = 'Sample', Company = 'Testing Sample Co' );
Lead objLead = utilityHelperTest.createLead();
insert objLead;
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId( objLead.Id );
//lc.setDoNotCreateOpportunity( true );
lc.setConvertedStatus( 'Closed - Converted' );
Database.LeadConvertResult lcr = Database.convertLead(lc, false);
system.debug( 'Errors are ' + lcr.getErrors() );
system.assert( lcr.isSuccess() );
}
}
@InvocableMethod(label='Convert the Lead' description='Convert the lead by LeadId and returns True/False as success/failures' category='Lead')
public static List<String> ConvertLead(List<ID> leadIds) {
List<String> convertedLeads= new List<String>();
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
for (String leadId: leadIds) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadId);
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr ;
try{
lcr = Database.convertLead(lc);
system.debug('*****lcr.isSuccess()'+lcr.isSuccess());
convertedLeads.add(LeadId);
}
catch(exception ex){
system.debug('***LEAD NOT CONVERTED**');
}
}
return convertedLeads;
}
}
i wants to test this class as per below Test class but not covering the code please anyone help me to find the issue in Test class
@isTest
private class cfg_LeadUtilityTest {
static testMethod void testLeadConv() {
//Lead objLead = new Lead( FirstName = 'Test', LastName = 'Sample', Company = 'Testing Sample Co' );
Lead objLead = utilityHelperTest.createLead();
insert objLead;
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId( objLead.Id );
//lc.setDoNotCreateOpportunity( true );
lc.setConvertedStatus( 'Closed - Converted' );
Database.LeadConvertResult lcr = Database.convertLead(lc, false);
system.debug( 'Errors are ' + lcr.getErrors() );
system.assert( lcr.isSuccess() );
}
}
Here's an example of how you could modify the cfg_LeadUtilityTest class to test the cfg_LeadUtility class:
This test class creates a new lead record, calls the ConvertLead method in cfg_LeadUtility class, and then asserts that the lead was successfully converted by checking that its status is updated to the converted status and that it is no longer a lead record.
Hope it helps !