You need to sign in to do that
Don't have an account?
Tyler Larrabee
Trying to understand why line is needed
I'm going through the trailhead course on Apex and I am trying to understand why 'return acct;' is a necessary line in this class.
public class AccountHandler { public static Account insertNewAccount(String name) { Account acct = new Account(Name= name); insert acct; return acct; } }Originally I wrote this class without searching the developer community for the answer. The only thing I was missing was 'return acct;'. I'm trying to understand why that line is needed.
The return type of the method is Account for this. So it should return an account.
If you use void you dont have to reutn the account
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm
Please mark it as best if it is useful.