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{

    public String objectkey;


    global class Response{

    public String entityObjectName;

    public Id objectMdtId;}

        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;


    return erList;}

Last line of test class is the issue:

private class Invocable_ObjectEntityDefinition_Test {

    static void GetObjectName(){

    List<String> objid = new list <String>();
        }catch (System.DmlException e){
                System.debug('DML Exception: ' +
            } catch (System.ListException e){
                System.debug('List Exception: ' +

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 };
| improve this answer | |

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.

| improve this answer | |

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.