My understanding of the Getter Setter is that getter is invoked if the particular variable is being referenced in VF Page.
However for the following code I see that Getter is getting called even if no variable reference is on the page.
public class EmbeddedTest
{
public list<account> lAcc{
get{
system.debug('INSIDE GETTER');
return null;
}
set;
}
public void checkChanges()
{
lAcc=[select id,name from account limit 10];
system.debug('ACCOUNT LOG GENERATED '+lAcc);
}
}
VF Page:
<apex:page controller="EmbeddedTest">
<apex:form >
<apex:commandButton action="{!checkChanges}" value="Click to change!"/>
</apex:form>
</apex:page>
On clicking the button I see the below logs(in order):
08:37:22.0 (14537986)|SOQL_EXECUTE_BEGIN|[19]|Aggregations:0|SELECT id, name FROM account LIMIT 10
08:37:22.0 (19987384)|SOQL_EXECUTE_END|[19]|Rows:10
08:37:22.0 (20434238)|USER_DEBUG|[3]|DEBUG|INSIDE GETTER
08:37:22.0 (20537127)|USER_DEBUG|[20]|DEBUG|ACCOUNT LOG GENERATED null
Why does the Getter get called and make the list(lAcc) null even without any VF reference ?