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
bremmibremmi 

how do i retrieve the list of records from custom obj to vf page when certain criteria matched

hello,

 i have two picklist  fields(single select ) in visualforce page like select _state and select_city. when i choose values  it has to disply total records list line by line   form the custome object by satisfying criteria otherwise throw an error like 'no records found for u criteria'. (using vf,apex,custom object)

Chamil MadusankaChamil Madusanka

I have created a sample custom object and simulate your scenario. You can use this example and apply your custom object.

 

This is the visualforce page

<apex:page controller="TestBoard20Controller">


  <apex:form > 
  <apex:pageBlock >
  <apex:pageBlockSection >
     
          <apex:inputField value="{!SearchCriteria.Field1__c}"/>
      
          <apex:inputField value="{!SearchCriteria.Status__c}"/>
          
          <apex:commandButton value="Search" action="{!filterApplicant}" reRender="applicantTbl,error"/>
      
  </apex:pageBlockSection>
  
      <apex:pageBlockTable styleClass="appTbl" id="applicantTbl" value="{!FilteredApplicants}" var="applicant">
          <apex:column value="{!applicant.Name}"/>
          <apex:column value="{!applicant.Company__c}"/>
          <apex:column value="{!applicant.Field1__c}"/>
          <apex:column value="{!applicant.Interview_Date_Time__c}"/>
          <apex:column value="{!applicant.Name__c}"/>
          <apex:column value="{!applicant.Status__c}"/>          
      </apex:pageBlockTable>
      
      <apex:pageMessages id="error"></apex:pageMessages>
  </apex:pageBlock>
  
    </apex:form>
</apex:page>

 

 

This is the controller

public with sharing class TestBoard20Controller {
    public List<Applicant__c> FilteredApplicants{get;set;}
    public String SelectedValue1{get;set;}
    public String SelectedValue2{get;set;}
    public Applicant__c SearchCriteria{get;set;}
    
    public TestBoard20Controller ()
    {
        SearchCriteria = new Applicant__c();
    }
    
    public void filterApplicant()    
    {
        FilteredApplicants = new List<Applicant__c>();
        
        FilteredApplicants = [SELECT Id,
                                     Name,
                                     Company__c,
                                     Field1__c,
                                     Interview_Date_Time__c,
                                     Name__c,
                                     Status__c
                              FROM Applicant__c
                              WHERE Status__c =: SearchCriteria.Status__c
                              AND Field1__c =: SearchCriteria.Field1__c];
         if(FilteredApplicants.size() == 0)
         {
            Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display')); 
         }
    }
}

 This is just a basic example. You can modify this with jquery, javascript, etc.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

eshhheshhh
How i can create email template with this

Peter TheodorePeter Theodore
Thank you so much for this example! I've been searching for days for an example like this. Thanks for the help!