Activity Forums Salesforce® Discussions Why Are Properties Helpful In Controllers?

  • shariq

    Member
    September 11, 2018 at 4:11 pm

    Hi,

    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 helps!

  • Parul

    Member
    September 11, 2018 at 5:37 pm

    Beacause properties can do additional things in your code it is like a variable. 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.

     

    For example:

    Public class BasicClass {

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

     

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

How to Set Up Web Chat in Salesforce Service Cloud SFDC - Learn Salesforce Series with Algoworks

Video in

In this video, you will get to know what the webchat feature in Salesforce Service Cloud is all about. Learn how to - 1. Introduction … Continue reading How to Set Up Web Chat in Salesforce Service Cloud SFDC - Learn Salesforce Series with Algoworks