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
JBabuJBabu 

Unable to display value in a page.

Hi,

 

I am trying to display picklist field output in visualforce page in the page block section as shown below:

 

VF Page:

------------

<apex:page standardController="Account" extensions="VisualAccountExtension" title="Display Accounts" >

                          <!-- other lines of code -->

 <apex:pageBlockSection title="{!UserTypeValue} is the type ">

                <!-- other lines of code -->

</apex:page>

 

In the extension "VisualAccountExtension", I have mentioned as :

--------------------------------------------------

 

List<User> UserTypeList = new List<User>();

String UserTypeValue  {get;set:}

 

 

 public String getUserTypeValue()
    {
        return UserTypeValue;
    }    
    public void SetUserTypeValue()
    {
        UserTypeList = [select Type__c from User where Id =:UserInfo.getUserId()];
        UserTypeValue = UserTypeList[0].Type__c;        
    }   

 

But I am not getting any output, in the page block section just   "is the type" is being displayed but I am not seeing the value of "UserTypeValue" in the visual force page.

Can some please help me where am I going wrong?

 

Thanks,

Babu.

Best Answer chosen by Admin (Salesforce Developers) 
sbbsbb

I would move the following lines into the getter (before 'return'):

 

UserTypeList = [select Type__c from User where Id =:UserInfo.getUserId()];
UserTypeValue = UserTypeList[0].Type__c; 

 

All Answers

sbbsbb

I would move the following lines into the getter (before 'return'):

 

UserTypeList = [select Type__c from User where Id =:UserInfo.getUserId()];
UserTypeValue = UserTypeList[0].Type__c; 

 

This was selected as the best answer
JBabuJBabu

Thanks a ton, it worked like charm.

I was in the conception that setter method we have to initialize and getter method is used to return the values.

Can you please clarify me when to use the statements in getter and when to use in setter?

 

Thanks,

Babu.