• #29775
    Salesforce | Sanjana Sanjana #17
    Forcetalks

    What Is Property in Salesforce Apex?

    What Is Property in Salesforce Apex?

     

    #29777
    Salesforce | suniti suniti #20
    Forcetalks

    Hello Sanjana

    Salesforce 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.

    Thank you.

    #34096
    Salesforce | Parul Parul #2
    Forcetalks

    Property definitions include one or two code blocks, representing a get accessor and a set accessor:

    • The code in a get accessor executes when the property is read.
    • The code in a set accessor executes when the property is assigned a new value.

    Public class BasicClass {

    // Property declaration
    access_modifier return_type property_name {
    get {
    //Get accessor code block
    }
    set {
    //Set accessor code block
    }
    }
    }

     

    Thanks

    #34100
     Anjali #8
    Forcetalks

    Hi Sanjana

    An Apex property is similar to a variable; however, you can do additional things in your code to a property value before it is accessed or returned. Properties can be used to validate data before a change is made, to prompt an action when data is changed (such as altering the value of other member variables), or to expose data that is retrieved from some other source (such as another class).

    Property definitions include one or two code blocks, representing a get accessor and a set accessor:

    • The code in a get accessor executes when the property is read.
    • The code in a set accessor executes when the property is assigned a new value.

    If a property has only a get accessor, it is considered read only. If a property has only a set accessor, it is considered write only. A property with both accessors is considered read-write.

    Hope this may help you.

    Thankyou!

    #34108
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    An Apex property is similar to a variable.

    Property definitions include one or two code blocks, representing a get accessor and a set accessor:

    The code in a get accessor executes when the property is read.
    The code in a set accessor executes when the property is assigned a new value.

    Note the following:

    The body of the get accessor is similar to that of a method. It must return a value of the property type. Executing the get accessor is the same as reading the value of the variable.
    The get accessor must end in a return statement.
    We recommend that your get accessor not change the state of the object that it is defined on.
    The set accessor is similar to a method whose return type is void.
    When you assign a value to the property, the set accessor is invoked with an argument that provides the new value.
    When the set accessor is invoked, the system passes an implicit argument to the setter called value of the same data type as the property.
    Properties cannot be defined on interface.

    Hope this helps!

    #34134
    Forcetalks

    Hello,

    When u used property u can control get, set, access.

    In this example, if accountList = null and you try to get this value, at first accountList queried 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.

    Thanks.

Viewing 6 posts - 1 through 6 (of 6 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?