You need to sign in to do that
Don't have an account?

How to create a search page in below format
HI i want to create a search page in below format. Kindly help me in writing the soql query in controller when user enters the Values for Min and Max fields for Square Footage.

Below is the Visual force page code.
<apex:page Standardcontroller="Opportunity" extensions="Condosearchcontroller" showHeader="true">
<style type="text/css">
body {background: #F3F3EC; padding-top: 5px}
</style>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Find Units" action="{!search}"/>
<apex:commandButton value="Reset" action="{!Clear}"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true" html-formnovalidate="formnovalidate" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" collapsible="false">
<apex:inputText value="{!beds}" label="Beds" />
<apex:inputText value="{!SFminimum}" label="Min" />
<apex:inputText value="{!SFmaximum}" label="Max"/>
</apex:pageBlockSection>
<apex:pageblockTable value="{!Cond}" var="a" id="table">
<apex:column >
<apex:outputlink value="https://cs19.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
</apex:column>
<apex:column value="{!a.Beds__c}"/>
<apex:column value="{!a.Square_Footage__c}"/>
<apex:column value="{!a.Initial_List_Price__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
below is the Apex Controller i have written.
public with sharing class Condosearchcontroller {
public Condosearchcontroller() {
}
public list <Condo__c> Cond {get;set;}
public string beds {get;set;}
public string squarefootage {get;set;}
public string SFminimum {get;set;}
public string SFmaximum {get;set;}
public string InitialListPrice {get;set;}
public string ILPminimum {get;set;}
public string ILPmaximum {get;set;}
public Condosearchcontroller(ApexPages.StandardController controller) {
}
public void Search(){
string searchquery= 'select name,Beds__c,Square_Footage__c,Initial_List_Price__c from Condo__c where name!=NULL';
if (!beds.equals(''))
searchquery+= ' and Beds__c = '+beds+'';
if(!SFminimum.equals('') && SFmaximum.equals(''))
searchquery+= ' and Square_Footage__c >= '+SFminimum+' and Square_Footage__c <= '+SFmaximum+'';
Cond= Database.query(searchquery);
}
public void clear(){
Cond.clear();
}
}
Below is the Visual force page code.
<apex:page Standardcontroller="Opportunity" extensions="Condosearchcontroller" showHeader="true">
<style type="text/css">
body {background: #F3F3EC; padding-top: 5px}
</style>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Find Units" action="{!search}"/>
<apex:commandButton value="Reset" action="{!Clear}"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true" html-formnovalidate="formnovalidate" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" collapsible="false">
<apex:inputText value="{!beds}" label="Beds" />
<apex:inputText value="{!SFminimum}" label="Min" />
<apex:inputText value="{!SFmaximum}" label="Max"/>
</apex:pageBlockSection>
<apex:pageblockTable value="{!Cond}" var="a" id="table">
<apex:column >
<apex:outputlink value="https://cs19.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
</apex:column>
<apex:column value="{!a.Beds__c}"/>
<apex:column value="{!a.Square_Footage__c}"/>
<apex:column value="{!a.Initial_List_Price__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
below is the Apex Controller i have written.
public with sharing class Condosearchcontroller {
public Condosearchcontroller() {
}
public list <Condo__c> Cond {get;set;}
public string beds {get;set;}
public string squarefootage {get;set;}
public string SFminimum {get;set;}
public string SFmaximum {get;set;}
public string InitialListPrice {get;set;}
public string ILPminimum {get;set;}
public string ILPmaximum {get;set;}
public Condosearchcontroller(ApexPages.StandardController controller) {
}
public void Search(){
string searchquery= 'select name,Beds__c,Square_Footage__c,Initial_List_Price__c from Condo__c where name!=NULL';
if (!beds.equals(''))
searchquery+= ' and Beds__c = '+beds+'';
if(!SFminimum.equals('') && SFmaximum.equals(''))
searchquery+= ' and Square_Footage__c >= '+SFminimum+' and Square_Footage__c <= '+SFmaximum+'';
Cond= Database.query(searchquery);
}
public void clear(){
Cond.clear();
}
}
If you use the member variables with getter and setter methods in the controller then it will automatically set the values given in the visualforce page.
Regards,
Mahesh