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
Angel30Angel30 

Getter and Setter methods VF

Hi All,

I am reading through the vf guide however i am not able to visualize the difference between the get;set methods.
i understand that get method will basically fetch data from controller and display in vf page and setter methods are used to pass the values from page to the controller.

i see that there are different ways of writing this.1 is to put logic for each getter and setter method and another method is to just put {get; set;}
Can anybody tell me the difference and how it works .

Thanks a lot!! 
NagendraNagendra (Salesforce Developers) 
Hi Deepshikha,

Those two code examples are functionally equivalent. The following code creates a property with a basic getter and setter:
Public String name { get; set; }
The other forms come into play when you want to format or validate data in some way. For example, if you want names to have the first letter uppercase and the rest lowercase:
Public String name {
get { return name; }
set { name = value.toLowerCase().capitalize(); }
}
Is there any order of firing the getter and setter method? Is 'setter' method triggers first than 'getter' method?
No, only one or the other is called at a time. Any time you access the property, get is called. Any time you store a value, the set is called.

For more information please check with below links. Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra