You need to sign in to do that
Don't have an account?
Escape Apostrophe in SOQL query
Hi All,
I have a custom object where there is a field called lastname which stores name of customer.
Some customer name have apostrophe(') which throws exception while querying
In my controller i am querying to get the value from this field as :
CustomObject__c C = [SELECT lastname__c FROM CustomObject__c ];
and storing it in my controller varible as
string myVariable = C.lastname;
I get query exceptionas such
An Exception has occuredSystem.QueryException: line 1:207 mismatched character '<EOF>' expecting '''Select LastName , from CustomObject__c Where LastName='O'Testuser' )
This happens when i try to do some operation on customer having apostrophe.
same query works fine for other customer
Please tell me how can i escape unsafe character from a generic query like the above
It's urgent
Regards,
Subham
Hi,
You can use the String.escapeSingleQuotes method before passing the value to soql query.
For example:
c.lastname=String.escapeSingleQuotes(c.lastname);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
You can use the String.escapeSingleQuotes method before passing the value to soql query.
For example:
c.lastname=String.escapeSingleQuotes(c.lastname);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks mr jain,,,
It worked
Thanks a lot