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
sml9099sml9099 

Retrieve records from custom object based on input criteria.

Hi, 

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:pageBlockButtons>

             <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:pageBlockSectionItem>
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Results" rendered="{!pRec.size>0}">
                <apex:pageBlockTable value="{!pRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    

                 </apex:pageBlockTable>
               
           
       
            </apex:pageBlockSection>
            </apex:pageblock>    
           
           
              
               
           
    </apex:form>
</apex:page>
NK@BITNK@BIT
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(){
        Match=false;
        NoMatch=false;
        gmailRec=[select NKBIT__Phone__c, NKBIT__User_Name__c, NKBIT__Email__c from NKBIT__Gmail__c where NKBIT__User_Name__c Like :'%'+inputName+'%'];
        if(gmailRec.size()>0)
        {
            Match=true;
        }
        else
        {
            NoMatch=true;
        }
    }
}

----------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:pageBlockSectionItem>
                
                 <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:pageblockTable>
                     </apex:pageblockSectionItem>
                 </apex:outputPanel>
                
                 <apex:outputPanel id="recNotMatch">
                     <apex:pageBlockSectionItem rendered="{!NoMatch}"> Record Not Found!</apex:pageBlockSectionItem>
                 </apex:outputPanel>
             </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
sml9099sml9099
Hey , 

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