Apex property is similar to a variable, they can validate data before a change is made; they can prompt an action when data is changed, such as altering the value of other member variables; or they can expose data that is retrieved from some other source, such as another class.
As a common practice, if your question is answered, please choose 1 best answer. But you can give every answer a thumb up if that answer is helpful to you.
When u used property u can controle get, set, access.
In this example if accountList = null and you try to get this value, at first accountList queryed and return you list of account.
public Account[] accountList {
get {
if (accountList == null) {
accountList = [SELECT Id, Name FROM Account];
}
return accountList;
}
}
Tracking value changes. In this example when you set a or b value, sum property recalculate automaticaly.
public Integer sum {
get;
set;
}
public Integer a {
get {
if (a == null) a = 0;
return 0;
}
set {
sum = a + b;
}
}
public Integer b {
get {
if (b == null) b = 0;
}
set {
sum = a + b;
}
}
and more other examples. You need understund get, set concepts.
Apex property is similar to a variable, they can validate data before a change is made; they can prompt an action when data is changed, such as altering the value of other member variables; or they can expose data that is retrieved from some other source, such as another class.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
Thanks,
Alex
nb: i've just started learning Apex and quite challeenging to grasp certain concepts , apex doc not much helpful i wud say.
When u used property u can controle get, set, access.
In this example if accountList = null and you try to get this value, at first accountList queryed and return you list of account. Tracking value changes. In this example when you set a or b value, sum property recalculate automaticaly.
and more other examples. You need understund get, set concepts.
Thanks,
Alex
I have gone through your problem.
Please go through the below links:
Apex class:-
https://help.salesforce.com/articleView?id=code_manage_packages.htm&type=5
Apex access modifiers:-
https://salesforcelearningpoint.wordpress.com/2015/12/24/access-modifiers-in-salesforce-apex/
Apex method:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm
Apex Static and Instance Methods
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora