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

Unleashing Potential: A Strategic Roadmap to Salesforce Staff Augmentation

Blog in

In the vast landscape of business evolution, there exists a compass that navigates the treacherous waters of innovation and efficiency—Salesforce staff augmentation. This strategic beacon … Continue reading Unleashing Potential: A Strategic Roadmap to Salesforce Staff Augmentation

How A Leading Equipment Manufacturer Boosted its Sales Potential by Adopting Advanced Salesforce CPQ Solutions

Blog in

Decades ago, organizations relied on legacy systems to meet their CPQ requirements. Software systems have advanced significantly since then. Today, we have cutting-edge SaaS platforms that … Continue reading How A Leading Equipment Manufacturer Boosted its Sales Potential by Adopting Advanced Salesforce CPQ Solutions

Popular Salesforce Videos