You need to sign in to do that
Don't have an account?
Ashok Reddy 61
Getting query results in Workbench , Not in apex class/Script
Background : I need access account records in the apex class where name contains %
For example, the query should return below accounts
abcd10%
cdcd40%abcd
10%volume
When i execute below query i am getting results in the workbench
select id,name from Account where Name LIKE '%\%%'
the same query If I execute in Anonymous window/apex execute getting no results
For example, the query should return below accounts
abcd10%
cdcd40%abcd
10%volume
When i execute below query i am getting results in the workbench
select id,name from Account where Name LIKE '%\%%'
the same query If I execute in Anonymous window/apex execute getting no results
List<Account> accList = [select id,name from Account where Name LIKE '%\%%'];
system.debug('accList :::'+accList.size());
If we observe below image, it is appending extra / in the query and giving wrong results.
Can you please help me how to resolve this?
You can try Query like this.It worked for me
SELECT Id,Name from Account where Name LIKE '%\%'
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Tried below snipet and worked :)
string s='\\%';
system.debug('!!!!='+s);
String query = 'SELECT Id,name FROM Account WHERE Name LIKE \'%'+S+'%\'';
List<Account> accList = Database.query(query);
system.debug('accList :::'+accList);