You need to sign in to do that
Don't have an account?
Jeff Bryant 16
How to write a Test Class for @InvocableMethod
I'm having an issue with "Method does not exist or incorrect signature" on this test class...
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);
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
@isTest
private class AutoConvertLeadsTest {
@isTest
public static void testLeadInsert ()
{
List<Id> lListIds = new List<Id>();
List<Lead> lList = new List<Lead>();
Lead objLead = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company');
insert objLead;
lList = [SELECT Id FROM Lead];
for(Lead l : lList){
lListIds.add(l.Id);
}
insert lList;
Test.startTest();
AutoConvertLeadsTest.LeadAssign(lListIds);
Test.stopTest();
}
}
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);
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
@isTest
private class AutoConvertLeadsTest {
@isTest
public static void testLeadInsert ()
{
List<Id> lListIds = new List<Id>();
List<Lead> lList = new List<Lead>();
Lead objLead = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company');
insert objLead;
lList = [SELECT Id FROM Lead];
for(Lead l : lList){
lListIds.add(l.Id);
}
insert lList;
Test.startTest();
AutoConvertLeadsTest.LeadAssign(lListIds);
Test.stopTest();
}
}
Hope that your day is off to an amazing start. Your issue stems from a class not being instantiated. Please try the below test class and report back when you get the chance. Hope this helps and may God bless you abundantly.
Best Regards,
Anthony McDougald
Hope that your day is off to an amazing start. Please try the below class and report back if you have any issues. Hope this helps and may God bless you abundantly.
Best Regards,
Anthony McDougald