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);


    }
}
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);
| improve this answer | |
  • 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 Jun 4 '18 at 16:37

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.