You need to sign in to do that
Don't have an account?
SF API 9
Auto Lead Conversion invokable method TEST Class
I used the below apex class as an invokable method to work with process builder. The code will fire when a certain field on the Lead record is populated.
The class works perfectly:
Public class AutoConvertLeads
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead: LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
The test class below (that i found online) is not giving me the coverage that I need. Can someone help me??
@IsTest (SeeAllData=true) private class AutoConvertLead_Test{
/* This is a basic test which simulates the primary positive case for the
Conversion method of a Lead. */
public static testMethod void myUnitTest() {
// create a Lead
Lead lead=new Lead(LastName='TestDoe',FirstName='TestJane',Company='TestUnknown',Status='Warm Prospect',Addy_Account_id__c='1234566');
insert lead;
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('User');
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}
The class works perfectly:
Public class AutoConvertLeads
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead: LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead);
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
The test class below (that i found online) is not giving me the coverage that I need. Can someone help me??
@IsTest (SeeAllData=true) private class AutoConvertLead_Test{
/* This is a basic test which simulates the primary positive case for the
Conversion method of a Lead. */
public static testMethod void myUnitTest() {
// create a Lead
Lead lead=new Lead(LastName='TestDoe',FirstName='TestJane',Company='TestUnknown',Status='Warm Prospect',Addy_Account_id__c='1234566');
insert lead;
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('User');
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}
Try something like the below
basically your test class should invoke the class and methods defined in the class it is testing.
Regards
Andrew