You need to sign in to do that
Don't have an account?
huniverse
How to append one string to another
Hi,
I have query of simple select in controller. I want to search inputtext value whether they are null or not and based on that i am searching their value from Datatable. Now i am stuck with this query. Can anyone tell me how i can rearrange the query based on user input. If anyone has code then please explain with code as i am new bie to VF.
Thanks in Advance.
For this you just need to bind the variable as below.
select id from account where name = :variablename
Thank you Srini for your quick reply. i have already added like that. Below is my code I am binding Plz,Ort, Strasse custom field in datatable. here Plz,Ort, Strasse is inputtext in page..
<apex:pageBlock id="MyOpps">
<apex:dataTable value="{!MyList}" var="aOpp" width="100%">
<apex:column headerValue="AccountName">
<apex:outputText value="{!aOpp.Name}" id="grdSelect"/>
</apex:column>
<apex:column headerValue="Plz">
<apex:outputText value="{!aOpp.Plz__c}" id="plz"/>
</apex:column>
<apex:column headerValue="Ort">
<apex:outputText value="{!aOpp.Ort__c}" id="ort"/>
</apex:column>
<apex:column headerValue="Strasse">
<apex:outputText value="{!aOpp.Strasse__c}" id="Strasse"/>
</apex:column>
<apex:column headerValue="Kundentyp">
</apex:column>
<apex:column headerValue="Aktiv">
</apex:column>
<apex:column headerValue="Besucht">
</apex:column>
</apex:dataTable>
</apex:pageBlock>
Controller code is
public List<Account> SelectPlz {get; set;}
public List<Account> bMyList(){
List<Account> con = new List<Account>();
MyList=[select Name, PLZ__c, Ort__c, Strasse__c from Account];
return MyList;
}
public PageReference genMyList() {
MyList = bMyList();
return null;
}
Currently search result is all records with or without custom fields. I want to search Plz,Ort,Strasse records through inputtext. e.g., Plz custom field is set to value 2 for any account then if i write plz value 2 in corresponding inputtext then it should search only record having plz value 2. Same search for other inputtext. i want to implement this search for 3 custom fields. my question is how to create query based on user inputtext.
Kindly guide me.
Thanks
You can try with permutations and combinations which is not really worth if you have more search fields
If you have more search fields then you can try with the dynamic apex.
Here is the link for your quick reference.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic.htm
Here is another good example from
http://blog.sforce.com/sforce/2008/09/in-my-last-post.html