i have string variable called "Identifier" which has apostrophe in it.
example: Identifier = "string's length"
i need to replace this apostrophe with "\'"
the result should be Identifier = "string\'s length"
finally i have to use this string variable in a database.query();
for example: below is the query string
String query = 'Select Id, Identifier__c from CustomObj__c where Identifier__c =' +Identifier;
And use this query in database.query()
like below
database.query(query);
Best Answer
give try this once. there is one method that do it for you, escapeSingleQuotes() .