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
JimmyMacJimmyMac 

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

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JimmyMacJimmyMac

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

souvik9086souvik9086

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

 

JimmyMacJimmyMac

Thanks but it didn't work.

 

Error: Variable does not exist Y

JimmyMacJimmyMac

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') + '\'');

This was selected as the best answer
souvik9086souvik9086

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