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
SriramR14SriramR14 

can anyone help me? why vf page nor displaying the sobject records?

public class Soql_example_5 
{
    public string searchText    {set;get;}
    public string query            {set;get;}
    public List<Account> accounts        {set;get;}
    
    public void fetchData()
    {
      string query='select id, name, phone, industry from Account where name like \' % '+searchText+' % \' ';
        accounts =Database.query(query);
    }
}

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

<apex:page controller="Soql_example_5">
    <apex:form id="fm">
         
        <apex:inputText value="{!searchText}"/> 
        <apex:commandButton value="Go" action="{!fetchData}" reRender="fm"/><br/><br/>
 
     <apex:pageblock>
          <apex:pageBlockSection>
            <apex:pageBlockSectionitem>
        <apex:pageBlockTable value="{!accounts}" var="a" cellpadding="50" width="2000" rules="rows" border="frame" rendered="{!NOT(ISNULL(accounts))}">
            <apex:column value="{!a.name}" headervalue="Name"/>
            <apex:column value="{!a.phone}" headervalue="Phone"/>
            <apex:column value="{!a.industry}" headervalue="Industry"/>
        </apex:pageBlockTable>
        </apex:pageBlockSectionitem>
    </apex:pageBlockSection>
            </apex:pageblock>
    </apex:form>
</apex:page>
SwethaSwetha (Salesforce Developers) 
HI Sriram,
I see that your query in apex class has spaces which is why the result fetched is not returning the expected rows

Please change from 
string query='select id, name, phone, industry from Account where name like \' % '+searchText+' % \' ';
to
string query='select id, name, phone, industry from Account where name like \'%'+searchText+'%\'';

I was able to fetch results after making above change in my org with your code.

As a general practice, to start troubleshooting I recommend adding system.debug() statements in your code to understand at which step the problem lies.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
SriramR14SriramR14
Hi,
Thanks, i got it.,

Sriram.R