1

I want to write a test class to test an Invocable Method. Is it possible to do this without using the Process Builder to initialize my Invocable Variables? The code for the class I want to test is pasted below.

global class DSSendtoQueue {

@InvocableMethod
public static void DSSendtoQueue(List<sobjectsListRequests> requests)
{   
    System.debug('In Invocable Method');
    ID OBID;
    ID UID;
    String phoneNum;
    Datetime callBackTime;

    for (sobjectsListRequests request : requests)
    {
        OBID = request.OBID;
        UID = request.UID;
        phoneNum = '1234657890'; //request.phoneNum;
        callBackTime = request.callBackTime;
        system.debug('Time = ' + callBackTime);
    }


            try
            {
                DSSendtoBackend RTPQ = new DSSendtoBackend(UID, OBID, phoneNum, callBackTime/*priorityScore, groupNumber*/);
                ID jobID = System.enqueueJob(RTPQ);
            }
            catch(exception e)
            {
                System.debug('Failed to enqueue batch job.  Error: ' + e);
            }            
}

global class sobjectsListRequests
{
    @InvocableVariable(required=True)
    public Id OBID;
    @InvocableVariable(required=True)
    public Id UID;
    @InvocableVariable(required=False)
    public String phoneNum;
    @InvocableVariable(required=False)
    public Datetime callBackTime;
}

}

4

Yes - the @Invocable... annotations provide extra data to the Process Builder. The code is still a normal Apex class whose methods you can call and fields you can set from a test class or any other Apex code.

| improve this answer | |
  • Yeah, you're right. I can't believe I thought I couldn't do that for some reason. Thanks! – user2278489 Sep 16 '16 at 20:27

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.