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!

  • [adinserter block='9']
  • 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

Email-to-Case Capabilities

How to Enhance Salesforce’s Standard Email-to-Case Capabilities to Deliver Top-Class Customer Service in 2023?

Blog in

“Happy customers are your biggest advocates and can become your most successful sales team.” – Lisa Masiello Did you know that 93% of customers are more … Continue reading How to Enhance Salesforce’s Standard Email-to-Case Capabilities to Deliver Top-Class Customer Service in 2023?

Popular Salesforce Videos

Developing an Automated Salesforce Data Quality Process

Video in

Learn how to create a harmonious and automated Salesforce data quality process with easy to customize tools and best practices. Beginning with the identification of … Continue reading Developing an Automated Salesforce Data Quality Process