1

I'm not getting coverage for this class, as it would be to test @invocableMethod

    global class CallFraudPreventionEventLogs implements Schedulable { 

    global void execute(SchedulableContext ctx) { 
        GenerateFraudPreventionEventLogView gfp = new GenerateFraudPreventionEventLogView(); 
        gfp.executeLog(); 
    }

    @invocableMethod
    public static void executeCallFraudPreventionEventLog() {         
        GenerateFraudPreventionEventLogView gfp = new GenerateFraudPreventionEventLogView(); 
        gfp.executeLog(); 
    }
}

Test Class

@isTest
public class CallFraudPreventionEventLogsTest {
    static TestMethod void TestOne(){      
        Test.startTest();     
        new CallFraudPreventionEventLogs().execute(null);               
        Test.stopTest(); 
    }
    
    public static TestMethod void testTwo() {
    Test.startTest(); 
        CallFraudPreventionEventLogs.executeCallFraudPreventionEventLog();
    Test.stopTest(); 
    }
}
  • As with any Apex test, you simply have to invoke the code (call the static method) and validate the results. – David Reed Nov 1 '20 at 3:34
  • @DavidReed Thanks for the support, friend, hugs! – Célio Xavier Nov 1 '20 at 3:55
  • Hi, and welcome to SFSE! It's considered bad form to edit the question to include the answer (see How to Ask, How to Answer and Can I answer my own question?). Please consider reverting your question and adding the code as an answer. Simply putting "Solved" in the title does not "solve" the question. After adding your own answer, you can ✔ your answer to let others know it was the answer that solved your problem. – sfdcfox Nov 1 '20 at 4:09
  • @sfdcfox A thousand pardons, I will correct! – Célio Xavier Nov 1 '20 at 4:17
  • The answer section is lower, this is just a comment area. There's a blue button down lower that should read "Answer your own question" or something to that effect. Just copy-paste your code and a brief summary of the solution in that box, and you'll be good. I could do it for you, but I don't want to take your rep away from you, so I'd rather you do it yourself. – sfdcfox Nov 1 '20 at 4:24
2

Passing the parameter as null is possible to complete the test successfully, and for @InvocableMethod it is only to perform the normal test.

@isTest
public class CallFraudPreventionEventLogsTest {
    static TestMethod void TestOne(){      
        Test.startTest();     
        new CallFraudPreventionEventLogs().execute(null);               
        Test.stopTest(); 
    }
    
    public static TestMethod void testTwo() {
    Test.startTest(); 
        CallFraudPreventionEventLogs.executeCallFraudPreventionEventLog();
    Test.stopTest(); 
    }
}
  • There you go! I cleaned it up for you as an example for you to use in the future. I hope that you enjoy your experience here and come back as often as you need! – sfdcfox Nov 1 '20 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.