You need to sign in to do that
Don't have an account?
shri k
Soql to search Accounts containing (_) underscore
I want to search Accounts which contains underscores, suppose I have accounts with names test,test_123,test_test,test_456 and when i fire following query it is returning me 4 rows where it should return 3only.
Query :
select id from account where name like '%test_%'
Salesforce considers ( _ ) as any single charatcter and thats why it is returning me 4 rows is there any way to overcome this. I have tried using escape sequence '%test\_%' but it is also not working.
Any pointers??
so then you need to escape the \ and do it like this
String searchString = '%test\\_%';
Worked for me it only returns Accounts Test_1 and Test_2
while the
String searchString = '%test_%';
version
also returns accounts like "Test Account"
All Answers
Not working with \\ too :(
SELECT Id,Name FROM Account WHERE Name LIKE '%test\_%' works fine for me !!
Yup that works fine!!
but consider the fillowing case
String searchString = '%test\_%';
List<Account> lstAcc = [select id from Account where Name like : searchString];
or
you can execute your own query in developer console not in Query editior it works in Query editor or force.com explorer but in the step i writtent above, this is not valid sequence for Salesforce
so then you need to escape the \ and do it like this
String searchString = '%test\\_%';
Worked for me it only returns Accounts Test_1 and Test_2
while the
String searchString = '%test_%';
version
also returns accounts like "Test Account"