You need to sign in to do that
Don't have an account?

How to Escape a quote in SOQL string
The below string works:
mystr = 'SELECT payout__Account_Desc__c FROM payout__ImportStaging__c where payout__BD_Id__c = \'' + bdId + '\'');
I want to add the following to the string:
and payout__Processed_Flag__c <> 'Y'
but am having an issue with the single quotes around the Y when trying to get the escape syntax correct....
Can somone please give me the correct syntax and what the complete mystr would look like ?
Thanks in advance.
-Jim
I added the 'Y' and it worked... Thank you.
mystr = 'SELECT payout__Account_Desc__c FROM payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(bdId) + '\' AND payout__Processed_Flag__c <> \'' + String.escapeSingleQuotes('Y') + '\'');
All Answers
Hi, Try this
mystr = 'SELECT payout__Account_Desc__c FROM payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(bdId) + '\' AND payout__Processed_Flag__c <> \'' + String.escapeSingleQuotes(Y) + '\'');
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thanks but it didn't work.
Error: Variable does not exist Y
I added the 'Y' and it worked... Thank you.
mystr = 'SELECT payout__Account_Desc__c FROM payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(bdId) + '\' AND payout__Processed_Flag__c <> \'' + String.escapeSingleQuotes('Y') + '\'');
You mean Y is not a variable.it is just a string that you want to add?. Then do it like this
mystr = 'SELECT payout__Account_Desc__c FROM payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(bdId) + '\' AND payout__Processed_Flag__c <> \' Y \'');
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks