I having a problem getting the ID of the entity company selected from the dropdownlist. The value passes correctly to the class, but the SOQL query is returning the ID of the Company.com-KY even if I select one of the other ones. I am preatty sure that the problem is because I am using this: WHERE Name LIKE \'%'+String.escapeSingleQuotes(l)+'%\' LIMIT 1';
My question is if there is another way to get the Id using for example 'Where name ='
I already tried this:
soql = 'SELECT Id FROM Entity_c WHERE Name='+String.escapeSingleQuotes(l)+''; soql = 'SELECT Id FROM Entity_c WHERE Name= \'%'+String.escapeSingleQuotes(l)+'%\' ';
Thank you!
Here is my VF page dropdown list
<select id="list" size="1" onChange="doSearch();" >
<option value="-" selected="selected">Select Entity</option>
<option value="Company" >Company</option>
<option value="Company.com">Company.com</option>
<option value="Company.com-KY">Company.com-KY</option>
</select>
Here is the class
public PageReference runSearch() {
String entity = Apexpages.currentPage().getParameters().get('list');
soql = 'SELECT Id FROM Entity__c WHERE Name like \'%'+String.escapeSingleQuotes(entity)+'%\' LIMIT 1';
runQuery();
return null;
}
here is query and how assign the entity id to a variable
public void runQuery() {
try {
entity = Database.query(soql);
objectlist =String.valueOf(entity);
msg = 'Entity selected successfully !';
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}