+ Start a Discussion

Help with passing variables to soql.

Hi, I was wondering how to pass a variable to soql. I am trying to make a vf page that has three parameters and a button. I want to enter in the values and then hit the submit button. This would then search through my object for the three parameters and if there is a match display that person's data. For example, John doe, 1/12/2009, 1/20/2010. (These are the parameters). Thanks for any help you can give.




You have to assign the value in each of the text fields to a corresponding parameter in your controller.  Once you do this, you can use the parameter in your controller by passing it into a dynamic SOQL query.


Examples are below


VisualForce page:


<apex:page controller="testController">
 <apex:inputText value="{!inputValue}" id="theTextInput"/><br/>
 <apex:commandButton action="{!testAction}" value="testButton"/>



public class testController {

    public PageReference testAction() {
        List<Contact> arrContacts = [Select Id from Contact where LastName = :inputValue];
        // do something with the array here
        return null;

public String inputValue





Also to note, the VisualForce Developer's Guide (http://www.salesforce.com/us/developer/docs/pages/index.htm) has examples on how to do this, as well as many other tasks.


I would recommend taking a look at this as you get a chance, to familiarize yourself with the platform.  It has proved useful to me on many occasions.