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
Hari nadh babu EluruHari nadh babu Eluru 

Min Age and Max Age result can be show in another page

if user enter min age, max age . fetch all the students in btwn that min and max age

in above example try to load students in ascending order based on age

result can be shown in another page when clicked search button
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari,

Please try this code:

vf Page 1:

<apex:page Controller="yaQuestionStudentMinMaxAge" >    
<apex:form >        
<apex:pageBlock title="Student Age">            
<apex:pageBlockSection columns="1">                
Min Age<apex:inputText value="{!minage}"/>                
Max Age<apex:inputText value="{!maxage}"/>                  
</apex:pageBlockSection>            
<apex:pageBlockButtons >                
<apex:commandButton action="{!search}" value="Search"/>            
</apex:pageBlockButtons>                        
</apex:pageBlock>      
</apex:form>
</apex:page>

Vf page 2:
<apex:page controller="yaQuestionStudentMinMaxAge" action="{!search1}">
     <apex:form >
         
        <apex:pageBlock title="Student Age">
             <apex:pageBlockTable value="{!studentObj}" var="c">
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.minAge__c}"/>
                <apex:column value="{!c.maxAge__c}"/>            
            </apex:pageBlockTable>     
         </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class:

public class yaQuestionStudentMinMaxAge {    
public string maxage{get;set;}    
public string minage{get;set;}    
public List <Student__c> studentObj {get;set;}            
public PageReference search() {        
PageReference redirectPage = new PageReference('https://wise-impala-estvyo-dev-ed--c.visualforce.com/apex/jb?core.apexpages.request.devconsole=1');  //please put here your second vf page URL     
// system.debug('pageReference::'+redirectPage);                
redirectPage.getParameters().put('minimumage',minage);              
redirectPage.getParameters().put('maximumage',maxage);             r
edirectPage.setRedirect(true);        
return redirectPage;    

}    
public void search1(){          
integer minval = integer.valueof(ApexPages.currentPage().getParameters().get('minimumage'));        
 integer maxval = integer.valueof(ApexPages.currentPage().getParameters().get('maximumage'));        
studentObj = new list<Student__c>();        
studentObj=[select Name, minAge__c,maxAge__c from Student__c where minAge__c>=:minval AND maxAge__c<=:maxval ORDER  BY minAge__c ASC];
// you can sort the data in ascending order by minAge__c or maxAge__c.        
system.debug('studentObj'+studentObj);    
}
}

Hope this will help you.
Thanks