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
sonamsonam 

Values of custom object arent displayed in The Vf page

Accounts is a custom object.i have to retrieve the  account type on the basis of Name.
I am able to retrieve the id and i'm  getting  account type in debug. But, it isnt displayed in the VF page.
Please have a look at the code..

 

Given below is the code of Class and VF page

<apex:page controller="SearchByName">
 <apex:form >
  <apex:outputLabel style="font-weight:bold;" value="Search By Name" ></apex:outputLabel>
        <apex:inputText value="{!textData}"/> 
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs" status="status"/>
 </apex:form>
 <!------Doesnt print the first name and account type------->
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Accounts}" var="c" >
  <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:outputField value="{!c.First_Name__c}" />
  </apex:column>
  <apex:column >
                <apex:facet name="header">Account Type</apex:facet>
                <apex:outputField value="{!c.Account_Type__c}" />
  </apex:column>

     
  </apex:pageBlockTable>
  </apex:pageBlock>
  
     <!------------- Getting the value of var "c"------------>
   <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="searching...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    
                    <apex:dataList value="{!Accounts}" var="c">a:{!c}</apex:dataList>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
 </apex:page>

 

public class SearchByName
{
 List<Account__c> Accounts;
private String textdata = null;

    public String getTextData() { return textdata; }
    
    public void setTextData(String data) { textdata = data; }
    
        
        
        public void search(){            
           
            Accounts = Database.query('SELECT First_Name__c,Account_Type__c  FROM Account__c where First_Name__c = :textdata');
            system.debug('Accounts>>>>'+Accounts);
       }    
        public List<Account__c> getAccounts() {
                
                return Accounts;
        }
        
       
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Sonali BhardwajSonali Bhardwaj

You need rerender your Pageblock where you print name and account type. Put page block in an output panel and rerender it in search button. Below code should work.

<apex:page controller="SearchByName">
 <apex:form >
  <apex:outputLabel style="font-weight:bold;" value="Search By Name" ></apex:outputLabel>
        <apex:inputText value="{!textData}"/> 
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs, table" status="status"/>
 </apex:form>
 <!------Now it should print the first name and account type------->
<apex:outputpanel id="table">
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Accounts}" var="c" >
  <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:outputField value="{!c.First_Name__c}" />
  </apex:column>
  <apex:column >
                <apex:facet name="header">Account Type</apex:facet>
                <apex:outputField value="{!c.Account_Type__c}" />
  </apex:column>

     
  </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:outputPanel>

     <!------------- Getting the value of var "c"------------>
   <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="searching...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    
                    <apex:dataList value="{!Accounts}" var="c">a:{!c}</apex:dataList>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
 </apex:page>

 

 

All Answers

Sonali BhardwajSonali Bhardwaj

You need rerender your Pageblock where you print name and account type. Put page block in an output panel and rerender it in search button. Below code should work.

<apex:page controller="SearchByName">
 <apex:form >
  <apex:outputLabel style="font-weight:bold;" value="Search By Name" ></apex:outputLabel>
        <apex:inputText value="{!textData}"/> 
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs, table" status="status"/>
 </apex:form>
 <!------Now it should print the first name and account type------->
<apex:outputpanel id="table">
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Accounts}" var="c" >
  <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:outputField value="{!c.First_Name__c}" />
  </apex:column>
  <apex:column >
                <apex:facet name="header">Account Type</apex:facet>
                <apex:outputField value="{!c.Account_Type__c}" />
  </apex:column>

     
  </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:outputPanel>

     <!------------- Getting the value of var "c"------------>
   <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="searching...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    
                    <apex:dataList value="{!Accounts}" var="c">a:{!c}</apex:dataList>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
 </apex:page>

 

 

This was selected as the best answer
sonamsonam

Thank You so much...It worked.. :)