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
nitin sharmanitin sharma 

Visualforce gettter method

Hi,I have taken below given code direclty from the book.This example is trying to access the account records and show in the visual force page.At no point of time I see in the debulogs ,my system.debug method in the getAccount() methid getting executed

Aren't the following lines suppose to execute getAccount() function?That is not hapening and yet I am able to see record information on the page.


i see constructor gettting executed and my save method getting executed.However,getAccount() is not getting executed.Can somebody please explain?.I am sure I am missing something.Please help

<apex:inputField value="{!Account.name}"/>
                <apex:inputField value="{!Account.phone}"/>
                <apex:inputField value="{!Account.industry}"/>



public class NewAndExistingController{
    public Account account{get;private set;}
    public NewAndExistingController()
        {
       
            ID id=ApexPages.currentPage().getParameters().get('id');       
            account=(id==null)? new account():[select Name,Phone,Industry from Account where id=:id];
           
            System.debug('This statement is whithin the construcotr'+account);
       
        }
       
        public account getAccount()
        {
       
        System.debug('The getAccount method before it returns account information to the visual force page is'+account);
            return account;
       
        }
        public Pagereference save()
        {
            try
                {
               
                System.debug('This line is before the account information has been upserted in the database'+account);
                     upsert(account);
                }
       
        catch(System.DMLException d)
            {
       
                Apexpages.AddMessages(d);
                return null;//
//              System.debug('therasied exception is'+d.message());
                   
        }
        return null;
   } 
   }




<apex:page controller="NewAndExistingController" tabstyle="Account">
    <apex:form >
        <apex:pageBlock mode="Edit">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:inputField value="{!Account.name}"/>
                <apex:inputField value="{!Account.phone}"/>
                <apex:inputField value="{!Account.industry}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Dev.AshishDev.Ashish
Nitin,

Try with change in code statement as shown below in controller.

public class NewAndExistingController{
    public Account account;
    public NewAndExistingController()
     -----------------------
     -----------------------


Amritesh SahuAmritesh Sahu
Hi Nitin,

You have provided same name for variable(Account account) and getAccount(){vf page reads it as Account}.
Change the getAccount() method name to another name such as getAccountRecord().

Hope this helps.
Regards