function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lakshman Mugilakshman Mugi 

What are getter methods and setter methods?

VinayVinay (Salesforce Developers) 
Hi Lakshman,

Setter method will take the value from the visualforce page and stores to the Apex variable name.

Getter method will return a value to a visualforce page whenever a name variable is called.

Check below references:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_methods.htm
https://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
sachinarorasfsachinarorasf
Hi Lakshman,

The get (getter) method is used to pass value from controller to VF page while set (setter) is used to set the value back to the controller variable. 

The above two methods are the same and will return the same results. Only their style of coding is different.

But if you modify the getter setter method with the below code then it will change the result.

For example, the name is 'John'

 public String name {
         get { return name + 'Get Value';}
        set { name = value +' Set Value';}
In above code getter result will be "John Get Value' and Setter result will be "John Set Value"

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
lakshman Mugilakshman Mugi
Thank you sachin arora
sachinarorasfsachinarorasf
Glad to help Lakshman please mark its best answer so that others can also get the concept.
David jack 12David jack 12
Hello Lakshman
Getters and setters are used to protect your data. Getter method used to store the Apex variable name and insert the value from the Visualforce page(VP).
The setter is used to set the values, it returns the value to a visualforce page(VP)  when we need to call the name variable.
In simple setter used to set the value and a getter used to insert or get the values.