0

Asked and answered here many times but I'm not finding this scenario. Getting method does not exist error when trying to invoke this Apex Class in my test.

global with sharing class Invocable_ObjectEntityDefinition {

    global class Request{

    @InvocableVariable(required=true)
    public String objectkey;

    }

    global class Response{

    @InvocableVariable(required=false)
    public String entityObjectName;

    @InvocableVariable(required=false)
    public Id objectMdtId;}

    @InvocableMethod(label='GetObjectName')
        global static List<Response> GetObjectName(List<Request> requests)

    {List<Response> erList = new List<Response>();
        Response er = new Response();

    // Should return just a single object
    hdone__Object__mdt o = [SELECT id, hdone__Object_Sfdc__r.QualifiedApiName
    FROM hdone__Object__mdt Where hdone__Object_Sfdc__r.KeyPrefix =: requests[0].objectkey Limit 1];

    er.entityObjectName = o.hdone__Object_Sfdc__r.QualifiedApiName;
    er.objectMdtId = o.Id;

    erList.add(er);

    return erList;}
}

Last line of test class is the issue:

private class Invocable_ObjectEntityDefinition_Test {

    @isTest
    static void GetObjectName(){

    List<String> objid = new list <String>();
            try{
                objid.add('001');
        }catch (System.DmlException e){
                System.debug('DML Exception: ' +
                             e.getDmlMessage(0));
            } catch (System.ListException e){
                System.debug('List Exception: ' +
                            e.getMessage());
        Invocable_ObjectEntityDefinition.GetObjectName(objid);
0

Your method takes a List<Request>, not a List<String>.

MyClass.Request request = new MyClass.Request();
request.objectKey = SObjectType.Account.getKeyPrefix();
List<MyClass.Request> requests = new List<MyClass.Request> { request };
MyClass.myMethod(requests);
1

Your call does not match the signature of your InvocableMethod. This'll be easier to see if you annotate with the type of the variable and put the call side-by-side with the definition.

In your test class:

        (void) Invocable_ObjectEntityDefinition.GetObjectName(List<String> objid);

but in your definition:

    global static List<Response> GetObjectName(List<Request> requests)

Your InvocableMethod accepts a List<Request>, rather than a List<String>.

Your test class is also throwing away the List<Response> that the method returns. You'll probably want to capture that in a variable so that you can write assertions against it to validate the behavior.

You can also safely remove those try/catch blocks in your unit test. Those exceptions will not be thrown there.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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