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
intern24intern24 

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.

m_roarkm_roark

intern24,

 

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:form>
 <apex:inputText value="{!inputValue}" id="theTextInput"/><br/>
 <apex:commandButton action="{!testAction}" value="testButton"/>
 </apex:form>
</apex:page>

 Controller:

 

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
{
get;set;
}
}

 

 

 

m_roarkm_roark

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.