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
SFDC_DaveSFDC_Dave 

Help formatting script when getting input from a user

I am creating a simple Java Script to do Bulk Lead Conversion from a list view. I want to ask the user for the Account name to convert the leads to and include that Account name in a Query to see if it already exists. 

 

I can not find the right format to incorporate the Account Name the user inputted to add to my Query. Can someone please help?!

 

var AccountName=prompt("Select Account Name to Convert to",'' ); //this works fine

 

Not sure how to structure the Query to find existing Account names based on Account Name

 

var accts=sforce.connection.query("Select Id, Name from Account where Name like ?????????? ");

richardvrichardv

See SOQL documentation here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql.htm

 

To specifically answer your question, if you want to do a like search with wildcards, the following should work:

 

Select Id, Name from Account where Name like '%ab%'

 

Since you appear to be doing this in javascript via Ajax Toolkit, be sure to escape the user's input or else you'd be vulnerable to SOQL injection.

 

What's the reason you're doing this in javascript and not through VisualForce/Apex? 

 

-Richard Vanhook