0

ProcessHandlerShowAccounts class works, but I am trying to get my test class up to par to validate my data. I am getting a variable does not exist, not sure why Did I initiate the class wrong?

Also when I call the method from the test class handleNewAccounts with an array of object as a paramter, is it okay to pass it a LIST will this be an issue moving forward?

public class ProcessHandlerShowAccounts 
{
    public class AccountParameter
    {
        @InvocableVariable(required=true)
        public Id accountId;
        @InvocableVariable(required=true)
        public String name;
    }


    @InvocableMethod
    public static void handleNewAccounts(AccountParameter [] accountParameters) 
    {

        System.debug('Account Id: '+accountParameters[0].accountId);
        System.debug('Name: '+accountParameters[0].name);
     }
}

//Test Class
@isTest
public class ERPTestClass {

    @isTest static void testhandleNewAccounts()
    {
        ProcessHandlerShowAccounts p = new ProcessHandlerShowAccounts();
        List<ProcessHandlerShowAccounts.AccountParameter> testAcctList = new List <ProcessHandlerShowAccounts.AccountParameter>();
         //accountId & name variables do not exist
         testAcctList.accountId.add('0011C000WW210zZ5');
         testAcctList.name.add('create');

        ProcessHandlerShowAccounts.handleNewAccounts(testAcctList);


    }
}

1 Answer 1

2

Here's your problem:

List<ProcessHandlerShowAccounts.AccountParameter> testAcctList = new List <ProcessHandlerShowAccounts.AccountParameter>();
//accountId & name variables do not exist
testAcctList.accountId.add('0011C000WW210zZ5');
testAcctList.name.add('create');

Your testAcctList variable holds a List, and that type has no accountId nor name attributes. Instead, you need to cache a single instance which would have those properties.

ProcessHandlerShowAccounts.AccountParameter instance = new ProcessHandlerShowAccounts.AccountParameter();
instance.accountId = '001...';
instance.name = '...';
myList.add(instance);
1
  • I want AccountParameter to be an array because I will be adding multiple accountId & name so would I just implement ProcessHandlerShowAccounts.AccountParameter[] instance = new ProcessHandlerShowAccounts.AccountParameter();
    – nameishi
    Commented Jun 4, 2018 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .