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
surekhasurekha 

About LKE operator

Hi..

 

Actualy i need the records which are starts with letter 'a'  in Account object  .

i tried with the below query ,but it shows all the records..once i clock the button..

 

varacc=[select name from Account WHERE name LIKE 'a%'];

 

 

Thanks & Regards

   surekha

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Your search string is hardcoded to accounts starting with s:

 

varacc=[select name from Account WHERE name LIKE's%'];

 

You should change this to something like:

 

String searchStr=value1+'%';
varacc=[select name from Account WHERE name LIKE :searchStr];

 

Note that I've built the wildcarded search string outside of the query - I've found that I have to do that to dynamically bind in the string.

All Answers

bob_buzzardbob_buzzard

This works correctly in my dev org - I have one account beginning with 'A' and only that account is retrieved.

 

What button are you clicking?

surekhasurekha

Hi..

 

I'll send the whole program Plz check it..n rly me

 

VF Page:-

 

<apex:page controller="DisplayNames">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
Enter Letter:<apex:inputText value="{!value1}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Search" action="{!search}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable Value="{!SecRecords}" var="Show">
<apex:column value="{!Show.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Class:

 

public with sharing class DisplayNames
{
public String value1 { get; set; }
List<Account> varacc;
public void search()
{
varacc=[select name from Account WHERE name LIKE's%'];

}
public List<Account> getSecRecords()
{
return varacc;
}

}

 

Thanks & Regards

   surekha

bob_buzzardbob_buzzard

Your search string is hardcoded to accounts starting with s:

 

varacc=[select name from Account WHERE name LIKE's%'];

 

You should change this to something like:

 

String searchStr=value1+'%';
varacc=[select name from Account WHERE name LIKE :searchStr];

 

Note that I've built the wildcarded search string outside of the query - I've found that I have to do that to dynamically bind in the string.

This was selected as the best answer
surekhasurekha
Hi..Thanks a lot... Mr.Bob.Now its realy working nice..Thanks & Regards  surekha

 

..