public with sharing class Myfirstvfclass {
public list<Account> lacc { get; set; }
public Myfirstvfclass(){
lacc=new list<Account> ([select id from Account]);
}
}
3 Answers
The constructor syntax is incorrect.
We write constructor as a method() with no return type.
public with sharing class Myfirstvfclass {
public list<Account> lacc { get; set; }
public Myfirstvfclass() {
lacc=new list<Account> ([select id from Account]);
}
}
You can read more about Constructors in apex here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_constructors.htm
The signature for constructor is incorrect, you are missing the parenthesis for constructor.
Below line should be replaced
public Myfirstvfclass // Incorrect without parenthesis
with
public Myfirstvfclass() //correct way of defining the constructor
Your class should be
public with sharing class Myfirstvfclass {
public list<Account> lacc { get; set; }
public Myfirstvfclass(){
lacc=new list<Account> ([select id from Account]);
}
}
your constructor could be done in this way:
public with sharing class Myfirstvfclass {
public list<Account> lacc { get; set; }
public Myfirstvfclass() {
lacc=new list<Account> ([select id from Account]);
}
}
-
should not matter right? intance variable called from instance context? May 23, 2019 at 8:14
-
-
1
-
yup. I could delete, as your answer is better then mine, but I believe it is not recommended to delete May 23, 2019 at 11:26