You need to sign in to do that
Don't have an account?
Vidya Rani
How to fetch values entered by user on a search visual force page
Need HELP !
Created an Account search page with few fields. Result should only show records which satisfies values entered by users. Currently my result page is showing all the records as blank fields not filled by users is also getting queried. How to query for fields which are only entered by users and skip blank ones?
My Controller:
public class Searchaccts {
public List<Account> MAccounts{ get; set; }
public String name { get; set; }
public String Active { get; set; }
public String Priority { get; set; }
public String UpOpp { get; set; }
public Searchaccts(ApexPages.StandardController controller) {
}
public void Searchaccts() {
MAccounts= [select Id
,Name
,Active__c,CustomerPriority__c,UpsellOpportunity__c
from Account
where Name = :name
OR Active__c= :Active OR CustomerPriority__c = :Priority OR UpsellOpportunity__c = :UpOpp];
System.debug('SearchListt ' + MAccounts +'!');
}
}
My Page:
<apex:page StandardController="Account" extensions="Searchaccts" sidebar="true" id="newpage">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Begin Default Content REMOVE THIS
<apex:image value="http://bit.ly/17iLknp" styleClass="logo" /> -->
<p style="font-size:30px">This is a SEARCH page</p>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection columns="1" showHeader="true" title="Search Your Account" id="account-Search">
<apex:pageBlockSectionItem labelTitle="Choose Account Type" >
<!-- Person Account / Business Account :</h6> -->
<label> HCO/HCP: </label><apex:selectList id="ChooseAccount" size="1" required="true">
<apex:selectOption itemValue="None" itemLabel="--None--"/>
<apex:selectOption itemValue="HCP" itemLabel="Person Account"/>
<apex:selectOption itemValue="HCO" itemLabel="Business Account"/>
<apex:actionSupport event="onchange" rerender="newpage"/>
</apex:selectList>
</apex:pageBlockSectionItem> <br/>
<apex:inputField value="{!Account.Active__c}" id="Active" required="false"/> <br/>
<apex:inputField value="{!Account.Name}" id="Name" required="false" /><br/>
<apex:inputField value="{!Account.CustomerPriority__c}" id="Priority" required="false"/><br/>
<apex:inputField value="{!Account.UpsellOpportunity__c}" id="UpOpp" required="false" /><br/>
<apex:commandButton action="{!Searchaccts}" value="Search" id="theButton"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
<apex:pageBlock >
<apex:PageBlockSection >
<apex:pageBlockTable value="{!MAccounts}" var="c">
<apex:column >
<apex:facet name="header">Name</apex:facet>
{!c.Name}
</apex:column>
<apex:column >
<apex:facet name="header">Active</apex:facet>
{!c.Active__c}
</apex:column>
</apex:pageBlockTable>
</apex:PageBlockSection>
</apex:pageBlock>
<script>
$(document).ready(function(){
$("[id$=ChooseAccount]").change(function(){
if(this.value=="HCO"){
$("[id$=Active]").prop("disabled",true);
$("[id$=Name]").prop("disabled",false);
}
else if(this.value=="None"){
$("[id$=Name]").prop("disabled",false);
$("[id$=Active]").prop("disabled",false);
}
else{
$("[id$=Name]").prop("disabled",true);
$("[id$=Active]").prop("disabled",false);
}
});
});
</script>
<!-- End Default Content REMOVE THIS -->
</apex:page>
Created an Account search page with few fields. Result should only show records which satisfies values entered by users. Currently my result page is showing all the records as blank fields not filled by users is also getting queried. How to query for fields which are only entered by users and skip blank ones?
My Controller:
public class Searchaccts {
public List<Account> MAccounts{ get; set; }
public String name { get; set; }
public String Active { get; set; }
public String Priority { get; set; }
public String UpOpp { get; set; }
public Searchaccts(ApexPages.StandardController controller) {
}
public void Searchaccts() {
MAccounts= [select Id
,Name
,Active__c,CustomerPriority__c,UpsellOpportunity__c
from Account
where Name = :name
OR Active__c= :Active OR CustomerPriority__c = :Priority OR UpsellOpportunity__c = :UpOpp];
System.debug('SearchListt ' + MAccounts +'!');
}
}
My Page:
<apex:page StandardController="Account" extensions="Searchaccts" sidebar="true" id="newpage">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Begin Default Content REMOVE THIS
<apex:image value="http://bit.ly/17iLknp" styleClass="logo" /> -->
<p style="font-size:30px">This is a SEARCH page</p>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection columns="1" showHeader="true" title="Search Your Account" id="account-Search">
<apex:pageBlockSectionItem labelTitle="Choose Account Type" >
<!-- Person Account / Business Account :</h6> -->
<label> HCO/HCP: </label><apex:selectList id="ChooseAccount" size="1" required="true">
<apex:selectOption itemValue="None" itemLabel="--None--"/>
<apex:selectOption itemValue="HCP" itemLabel="Person Account"/>
<apex:selectOption itemValue="HCO" itemLabel="Business Account"/>
<apex:actionSupport event="onchange" rerender="newpage"/>
</apex:selectList>
</apex:pageBlockSectionItem> <br/>
<apex:inputField value="{!Account.Active__c}" id="Active" required="false"/> <br/>
<apex:inputField value="{!Account.Name}" id="Name" required="false" /><br/>
<apex:inputField value="{!Account.CustomerPriority__c}" id="Priority" required="false"/><br/>
<apex:inputField value="{!Account.UpsellOpportunity__c}" id="UpOpp" required="false" /><br/>
<apex:commandButton action="{!Searchaccts}" value="Search" id="theButton"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
<apex:pageBlock >
<apex:PageBlockSection >
<apex:pageBlockTable value="{!MAccounts}" var="c">
<apex:column >
<apex:facet name="header">Name</apex:facet>
{!c.Name}
</apex:column>
<apex:column >
<apex:facet name="header">Active</apex:facet>
{!c.Active__c}
</apex:column>
</apex:pageBlockTable>
</apex:PageBlockSection>
</apex:pageBlock>
<script>
$(document).ready(function(){
$("[id$=ChooseAccount]").change(function(){
if(this.value=="HCO"){
$("[id$=Active]").prop("disabled",true);
$("[id$=Name]").prop("disabled",false);
}
else if(this.value=="None"){
$("[id$=Name]").prop("disabled",false);
$("[id$=Active]").prop("disabled",false);
}
else{
$("[id$=Name]").prop("disabled",true);
$("[id$=Active]").prop("disabled",false);
}
});
});
</script>
<!-- End Default Content REMOVE THIS -->
</apex:page>