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
testortestor 

User input on apex.query with FLEX 2

With Flex 2, I'm trying to use TextInput to allow the user to enter information for the apex query, but haven't been able to successfully pass the information.
Here's how I retrieve the information:
      <mx:FormItem label="Enter an organization name to search: ">
          <mx:TextInput id="orgname" width="100%"/>
      </mx:FormItem>

Here's how I'm trying to use the data in the query:
     apex.query("Select Name, Phone, From Contact where account.name=orgname", new AsyncResponder(

Compiles fine, but when I run it, I get the following error:
(com.salesforce.results::Fault)#0
  detail = (Object)#1
    fault = (Object)#2
      column = 72
      exceptionCode = "MALFORMED_QUERY"
      exceptionMessage = "
From Contact where account.name=orgname
                                ^
ERROR at Row:1:Column:72
unexpected token: orgname"
      row = 1
      xsi:type = "sf:MalformedQueryFault"
  faultcode = "sf:MALFORMED_QUERY"
  faultstring = "MALFORMED_QUERY:
From Contact where account.name=orgname
                                ^
ERROR at Row:1:Column:72
unexpected token: orgname"


Jon L. DaviesJon L. Davies

Your SOQL statement should be:

Code:

"Select Name, Phone, From Contact where account.name='" + orgname.text + "'"


 

Note: This is not a search or a wildcard so your user will have to spell the Account Name correctly for it to return anything.

 

Jon Davies
360 Vantage
3115 S. Price Road
Chandler, AZ 85248

testortestor
Thanks!  That works.  Is that an Apex syntax?
Jon L. DaviesJon L. Davies
It is not specific to Salesforce.
 
Any time you are working with a string you should enclose it in qoute marks.
 
As for getting the value of the textbox you need to call the object, in this case orgname, then call the property you want.  In the case of a text box you want .text
 
 
Jon Davies
360 Vantage
3115 S. Price Road
Chandler, AZ 85248
testortestor
Thanks for all the help.  It's the plus signs that are totally unfamiliar to me . . . 

I've got the query working (with wildcards even), but now I need to add the Account.Name to my data grid.  The datafield can't be expressed as "Account.Name".  I tried to fox it with a subquery fetching first and last names from contact within the main query fetching name from account, but I couldn't get FirstName or LastName to work in the datafield with that query.  I don't want to use two arrays if I can avoid it.

I'd sure appreciate another bit of help!