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
rucharucha 

Variables vs Properties

Hi,

 

When should one use variables and when should properties be used? Does one have a technical advantage over other?

 

Thanks

 

Rucha

 

 

Jake GmerekJake Gmerek
Basically there is little technical difference between the two and really the decision should be based on code readability and reuse. My personal rule of thumb is that if I am going to use an object in more than one method I make it a property, but any object that is only used in one method I just use a variable for.
phani kumar 95phani kumar 95
to add to above, another difference i found : if you have a controller class: properties are accissible from visual force pages (ex: {!class.property}) and variables are not.
phani kumar 95phani kumar 95
yet another : if you are using variables, then you must have public getters/setters to use them in visulaforce page.the public properties are avaialble directly on apex pages.