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
Pruthvi KrishnaPruthvi Krishna 

Output on VisualForce Page

I have this apex class and VF page:

public class OppCompare
{
public String searchText;
   
public List<Opportunity> results;

    public String getSearchText() {
        return searchText;
    }
public void setSearchText(String s)
{
searchText = s;
}

    
public List<Opportunity> getResults() {
            return results;
        }

    public String OppCompare { get; set; }

    public String Opportunity { get; set; }
 public PageReference Fetch()
 {
 results = [select Id, Name, Description, Amount from Opportunity where Name = 'CJMTK'];
 return null;
 }

}
and the VF page is :

<apex:page Controller="OppCompare">
<apex:form >
  <apex:pageblock >
 <apex:pageBlockSection columns="2" id="Oppcompareblock" >
 <apex:inputText id="OppOriginal" value="{!searchText}"/>
 <apex:inputText id="OppDup" value="{!searchText}"/>
 <apex:commandButton value="Fetch" action="{!Fetch}"  />
  <apex:commandButton value="Fetch" action="{!Fetch}" />
  
   <apex:inputText value="{!results[0].Id}"/>
                  <apex:inputText value="{!results[0].Description}"/>
  
 </apex:pageBlockSection>
 <apex:pageBlockSection title="Results" id="results" columns="1">
          <apex:pageBlockTable value="{!results}" var="l"
                                   rendered="{!NOT(ISNULL(results))}">
                  <apex:inputText value="{!l.Id}"/>
                  <apex:inputText value="{!l.Description}"/>

               </apex:pageBlockTable>
   </apex:pageBlockSection>    
   <apex:pageBlockSection title="Results" id="results2" columns="1">      
                 <apex:pageBlockTable value="{!results}" var="l2"
                                   rendered="{!NOT(ISNULL(results))}">
                  <apex:inputText value="{!l2.Id}"/>
                  <apex:inputText value="{!l2.Description}"/>

               </apex:pageBlockTable>
  
  </apex:pageBlockSection>  
 
 </apex:pageblock>

</apex:form>
</apex:page>

But the l.ID and l.Description is not returning anything . The fields are blank . PLease help
Best Answer chosen by Pruthvi Krishna
Chandra Sekhar CH N VChandra Sekhar CH N V
Made few changes, (working for second pageblock, make similar changes for first block as well)

also, you are using a custom controller which will not display column headers in the tables. Instead would suggest you to go for standard controller.
 
<apex:page Controller="df10">
<apex:form >
  <apex:pageblock >
 <apex:pageBlockSection columns="2" id="Oppcompareblock" >
 <apex:inputText id="OppOriginal" value="{!searchText}"/>
 <apex:inputText id="OppDup" value="{!searchText}"/>
 <apex:commandButton value="Fetch" action="{!Fetch}" reRender="panel"/>
  <apex:commandButton value="Fetch" action="{!Fetch}" reRender="panel1" />  
 </apex:pageBlockSection>
      <apex:outputPanel id="panel">
 <apex:pageBlockSection title="Results" id="results" columns="1">
          <apex:pageBlockTable value="{!results}" var="opp">
     <apex:column><apex:outputText value="{!opp.Name}"/></apex:column>
                     <apex:column><apex:outputText value="{!opp.Description}"/></apex:column>
               </apex:pageBlockTable>
   </apex:pageBlockSection>  
          </apex:outputPanel>
      <apex:outputPanel id="panel1">
   <apex:pageBlockSection title="Results" id="results2" columns="1">      
                 <apex:pageBlockTable value="{!results}" var="l2">
                 <apex:column><apex:outputText value="{!l2.Name}"/></apex:column>
                     <apex:column><apex:outputText value="{!l2.Description}"/></apex:column>
               </apex:pageBlockTable>  
  </apex:pageBlockSection>  
 </apex:outputPanel>
 </apex:pageblock>
</apex:form>
</apex:page>


public class df10
{
public String searchText{get;set;}
public List<Opportunity> results{get;set;}
public String df10 { get; set; }
public void Fetch()
 {
 results = [select Name, Description, Amount from Opportunity where name =:searchText];
 }

}

 

All Answers

Chandra Sekhar CH N VChandra Sekhar CH N V
Are you displaying values from the VF page? In that case you need to use <apex:outputText>/<apex:outputField>
salesforce mesalesforce me
User-added image
Pruthvi KrishnaPruthvi Krishna
@Salesforceme,

How do you get that? I am struggling to get the output.
Pruthvi KrishnaPruthvi Krishna
@chandrasekhar,

I tried Outputfield, but I am getting this error:
Subscript is invalid because list is empty.

But I am sure the SOQL query has some rows to return. Can you please point out the error in my code or correct it?
Chandra Sekhar CH N VChandra Sekhar CH N V
Made few changes, (working for second pageblock, make similar changes for first block as well)

also, you are using a custom controller which will not display column headers in the tables. Instead would suggest you to go for standard controller.
 
<apex:page Controller="df10">
<apex:form >
  <apex:pageblock >
 <apex:pageBlockSection columns="2" id="Oppcompareblock" >
 <apex:inputText id="OppOriginal" value="{!searchText}"/>
 <apex:inputText id="OppDup" value="{!searchText}"/>
 <apex:commandButton value="Fetch" action="{!Fetch}" reRender="panel"/>
  <apex:commandButton value="Fetch" action="{!Fetch}" reRender="panel1" />  
 </apex:pageBlockSection>
      <apex:outputPanel id="panel">
 <apex:pageBlockSection title="Results" id="results" columns="1">
          <apex:pageBlockTable value="{!results}" var="opp">
     <apex:column><apex:outputText value="{!opp.Name}"/></apex:column>
                     <apex:column><apex:outputText value="{!opp.Description}"/></apex:column>
               </apex:pageBlockTable>
   </apex:pageBlockSection>  
          </apex:outputPanel>
      <apex:outputPanel id="panel1">
   <apex:pageBlockSection title="Results" id="results2" columns="1">      
                 <apex:pageBlockTable value="{!results}" var="l2">
                 <apex:column><apex:outputText value="{!l2.Name}"/></apex:column>
                     <apex:column><apex:outputText value="{!l2.Description}"/></apex:column>
               </apex:pageBlockTable>  
  </apex:pageBlockSection>  
 </apex:outputPanel>
 </apex:pageblock>
</apex:form>
</apex:page>


public class df10
{
public String searchText{get;set;}
public List<Opportunity> results{get;set;}
public String df10 { get; set; }
public void Fetch()
 {
 results = [select Name, Description, Amount from Opportunity where name =:searchText];
 }

}

 
This was selected as the best answer
Pruthvi KrishnaPruthvi Krishna
Thank you very much Chandra. I marked your answer as best.