15

Getter, Setter Method Part 1

What Is Getter And Setter Methods In Salesforce?

Getter and Setter methods are used to get and set the value of properties of a class, respectively. Here is the below example sample code for getter Setter methods.

How To Use Getter And Setter In Salesforce?

public class MyClass {
    private String myProperty;

    public String getMyProperty() {
        return myProperty;
    }

    public void setMyProperty(String value) {
        myProperty = value;
    }
}

In the above code, setMyProperty method is used to set the myProperty property value. getMyProperty method is used to get the myProperty value.

salesforce-developer
Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

Book A 15-Minutes Free Career Counselling Today!