You need to sign in to do that
Don't have an account?
Leticia Monteiro Freitas 4
Database.query with like
Hi,
I'm trying use a Database.query passing a string and a should use a like with operator '%'+a+'%.
String codeName ;
String query = 'Select ID, Name from Account where codeName like '%' + codeName + '%'.
What is the right syntax?
See the string codeName is a variable not a literal string.
I'm trying use a Database.query passing a string and a should use a like with operator '%'+a+'%.
String codeName ;
String query = 'Select ID, Name from Account where codeName like '%' + codeName + '%'.
What is the right syntax?
See the string codeName is a variable not a literal string.
Greetings to you!
You can escape new lines, carriage returns, tabs, quotes, and more. The escape character for SOQL is the backslash (\) character.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm
Dynamic SOQL:
Using Apex Variables:
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
Modify your Query as given below:
String query = 'Select ID, Name from Account where codeName like ';
String query2 = '\'%' + String.valueOf(codeName) + '%\'' ;
String finalquery= query+query2;
System.debug(Database.query(finalquery));
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Try the following code it may be helpful for you:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha