function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Patricia LimPatricia Lim 

Method does not exist or incorrect signature: void sObjectsInsert(Integer) from the type AccountHandler

Hi all, new to Apex here doing Trailhead..
I am receiving the error in the title above - here is my apex class:
 
public class AccountHandler {
    public static void insertAccount(Integer value){
        Integer counter = 1;
        //create a list
        List<Account> addAccounts = new List<Account>();
        while(counter <= value){
        //display current counter value
        system.debug('Counter value before incrementing' + counter);
        //create a new account
        Account store = new Account();
        store.Name = 'Acme Inc n' + counter;
        store.AccountNumber = 'A00n' + counter;
        addAccounts.add(store);
        system.debug(addAccounts);
        //increment counter
        counter = counter + 1;
        system.debug('Counter value after incrementing' + counter);     
        
        }
        system.debug('Size of Account list:' + addAccounts.size());
        system.debug('Elements in Account List:' + addAccounts);
        //insert
        insert addAccounts;
    }
}
And my execution code:
AccountHandler.sObjectsInsert(3);

 
Maharajan CMaharajan C
Hi Lim,

You are referring the method name wrongly:  sObjectsInsert ==> insertAccount

AccountHandler.insertAccount(3);

Thanks,
Maharajan.C

 
Andrew GAndrew G
To expand on Maharajan's response:
In short:
public class AccountHandler {     //<----- this is a class

    public static void insertAccount(Integer value){  //<---this is a method

//value is the parameter of type Integer

//code that does stuff

    }
}

The language or format for invoking a method is 
 
class.method(parameters);
//or if no parameters
class.method();
There are some variations, but above is the basic format.

regards
Andrew
Patricia LimPatricia Lim
Thanks everyone. Trailhead tutorial provided class.sObjectsInsert(parameters); for invoking in the debug window - when to use which?