+ Start a Discussion
PS81PS81 

what are apex properties

Hi

I've been reading on properties in apex but still bit confused on the actual use case of it. please can anyone help me to understand it?
Alexander TsitsuraAlexander Tsitsura
Hi Prabhu,

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
PS81PS81
Thankx Alex, i had already gone thru this doc ,though not much of help where i can clearly understand the user case.

nb: i've just started learning Apex and quite challeenging to grasp certain concepts , apex doc not much helpful i wud say.
Alexander TsitsuraAlexander Tsitsura
Hi Prabhu,

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.

Thanks,
Alex
sachinarorasfsachinarorasf
Hi,

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