function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KMK91KMK91 

How to write test class for @invocable method in apex ? Could you please advise me?

Best Answer chosen by KMK91
bob_buzzardbob_buzzard
You'd write it the same as any other test class. Set up the required data, execute the method and then verify the results. The invocable aspect is just an annotation that makes it available to particular areas of the Salesforce platform, you can still call it directly.

All Answers

bob_buzzardbob_buzzard
You'd write it the same as any other test class. Set up the required data, execute the method and then verify the results. The invocable aspect is just an annotation that makes it available to particular areas of the Salesforce platform, you can still call it directly.
This was selected as the best answer
KMK91KMK91
Thanks Bob
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Bob ,
   I am facing a similar issue. As per salesforce documentation "Process Flows are deactivated upon deployment". Now I have a scenario where a checkbox toggles from False to True in parent record , process flow fires and invokes an apex class, that class creates a child record related to that parent. Now at the time of deployment my process flow is deactivated , so when I query the child records in my test class I get the error "List has no rows for assignment". 

Now to compensate for the inactive flow how can I imitate the exact firing logic in my apex test class?

Regards
Shrey Tyagi
 

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com
Bob - I know you don't prefer giving out exact code in your recommendations, but here is my code. I find it easier to explain my situation through code here. Please help.

Thanks!!!

Test Class sample is given below:

@isTest
public class Test_PrasApexCode {
    
    static testMethod void testDoGet1() {
        
        
        
        Costpoint_Project__c testCostpointProject = new Costpoint_Project__c();
        testCostpointProject.Business_Unit__c='SSES';
        testCostpointProject.Unit__c='EHS';
        testCostpointProject.Division__c='Environment';
        testCostpointProject.Review_Required__c=False;
        testCostpointProject.Project_Manager__c=u1[0].Id;
        insert testCostpointProject;

        

       ///////////////////////Process flow fires here, checkbox changes from False to True//////////////////////////////////
        testCostpointProject.Review_Required__c=True;
        update testCostpointProject;
///////////////////////////////////////////////////////////////////////////////////////////////////

        

        
        
        //Fetch related Project Risk Review form.
       //This is where the error is thrown
        Project_Risk_Review__c ProRiskRev=[Select id,DVP__c,Project_Manager__c,Chair_Reviewer__c,Delegate__c 
                                           from Project_Risk_Review__c where Costpoint_Project__c=:testCostpointProject.Id Limit 1];

        
        ProRiskRev.Chair_Reviewer__c=u1[0].Id;
        ProRiskRev.DVP__c=u1[1].Id;
        Update ProRiskRev;


        

    
    }
    

}
Aditi Singh 54Aditi Singh 54
How you have solved this error