I have a simple invocable method (thanks, Rakesh Gupta!) that I'm calling from a Process Builder when certain criteria are met. I'm getting good results from the code as evidenced by reviewing data in the UI, but I'm not sure how to write a test class for an @InvocableMethod.
Here is the invocable method:
public class AssignLeadsUsingAssignmentRules
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead Leads=[select id from lead where lead.id in :LeadIds];
Leads.setOptions(dmo);
update Leads;
}
}
Here is test class that I've written:
@isTest
private class AssignLeadsUsingAssignmentRulesTest {
private static testMethod void doTest() {
Test.startTest();
Lead l = new Lead(LastName = 'Test Lead',
Company = 'Test Company',
IsRecruitmentLead__c = True);
insert l;
Test.stopTest();
}
}
The test class creates data that meets the criteria for the Process Builder, and the test class executes to completion in the Developer Console, but I'm still getting 0% code coverage for the invocable class.
Thanks in advance for your advice - Tom