+ Start a Discussion

Retrieve records from custom object based on input criteria.


I am creating a basic VF page in which user will enter something in EDUCATIONAL_REQUIREMENTS__c field and it will fetch the records from POSITION__c object which matches the field critirea. It is not giving me any error but it is also not fetching the reocrds based on the critirea. Kindly take a look . I believe, I am doing something wrong in SOQL query. Below is my VF page and APEX class.

public class positionFetch{

    public String sp { get; set; }
public POSITION__c  p{get;set;}
    public List<POSITION__c > pRec{get;set;}
    String matchString;
    public positionFetch(){
        p=new POSITION__c ();
        pRec = new List<POSITION__c>();
        matchString = '';
    public void FetchPRec(){
        matchString = '%'+p.EDUCATIONAL_REQUIREMENTS__c+'%';
        pRec=[select Name from POSITION__c WHERE (Name like :matchString) ];

VF page:

<apex:page controller="positionFetch" >
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockButtons location="Top">
            <apex:commandButton value="Fetch" action="{!FetchPRec}"/>


             <apex:pageBlockSection title="Please select the Critirea">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Requirement" for="autoplay"/>
                    <apex:inputText value="{!p.EDUCATIONAL_REQUIREMENTS__c}" id="autoplay"/>
            <apex:pageBlockSection title="Results" rendered="{!pRec.size>0}">
                <apex:pageBlockTable value="{!pRec}" var="site" >
                    <apex:column value="{!site.Name}"/>

Try like this...

---------VisualForce Page---------

public class GmailFetch{
    public NKBIT__Gmail__c gm{get;set;}
    public List<NKBIT__Gmail__c> gmailRec{get;set;} 
    public Boolean Match{get;set;}
    public Boolean NoMatch{get;set;}
    public String inputName{get;set;}
    public GmailFetch(){
        gm=new NKBIT__Gmail__c();
    public void createTableGmailRec(){
        gmailRec=[select NKBIT__Phone__c, NKBIT__User_Name__c, NKBIT__Email__c from NKBIT__Gmail__c where NKBIT__User_Name__c Like :'%'+inputName+'%'];

----------Apex Class-----------

<apex:page controller="GmailFetch">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >             
             <apex:pageblockSection title="Record Table">
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="Enter Name" for="username"/>
                     <apex:inputText value="{!inputName}" id="username"/>
                 <apex:commandButton value="Record!" action="{!createTableGmailRec}" reRender="recMatch, recNotMatch"/>
                 <apex:outputPanel id="recMatch">
                     <apex:pageblockSectionItem rendered="{!Match}">
                         <apex:pageblockTable value="{!gmailRec}" var="gmail">
                             <apex:column value="{!gmail.Phone__c}"/>
                             <apex:column value="{!gmail.Email__c}"/>
                 <apex:outputPanel id="recNotMatch">
                     <apex:pageBlockSectionItem rendered="{!NoMatch}"> Record Not Found!</apex:pageBlockSectionItem>
Hey , 

Thanks for your reply. I actually figured it out. I was doing some stupid mistake.