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
Chandramohan Yetukuri 1Chandramohan Yetukuri 1 

I have one basic question...what is the significance of get and set in the code.

Hi Friends,
I have the below line something like this in one of the apex classs..
public String productCode {get;set;}
What is the impact if i remove {get;set;} and simply keep like this......"public String productCode"
Can someone explain.

Regards,
Chandra



 
Malni Chandrasekaran 2Malni Chandrasekaran 2
Chandramohan,
A variable becomes a property when we define with 'get, set' methods. otherwise it remains as a member variable.

The main advantage of defining a variable as property is 
  • you can add some validation while getting or setting the data in get/set method
  • you can make it read only or write only by defining either get or set method only respectively.
Please refer,
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_properties.htm


Please mark it as solved if this answers your question.

Thanks.
Chandramohan Yetukuri 1Chandramohan Yetukuri 1
Thanks Malni. I appriciate your explanation.