[SalesForce] Include single quotation mark in string

I'm trying to add a single quote to the following code

if(txo.Target__c != null){
                       targetsToCreate.add(txo);
                   }else{
                       o.addError(' Please ask your Salesforce Administrator to add a target record, for the month & year of your Opportunity's close date');
                   }

so that my string is displayed as

Please ask your Salesforce Administrator to add a target record, for the month & year of your Opportunity's close date.

The above causes the error

line breaks not allowed in string literals

Having found various 'solutions', I've tried Opportunity''s, Opportunity\\\\'s, Opportunity\'\'s and

" Please ask your Salesforce Administrator to add a target record, for the month & year of your Opportunity's close date"

but none of the above work.

How can I include the single quotation mark in my string?

Best Answer

This way it works:

trigger SingleQuote on Account (after insert) {
   Trigger.New[0].addError(' Please ask your Salesforce Administrator to add a target record, for the month & year of your Opportunity\'s close date');
}

enter image description here

AND

enter image description here

AND

enter image description here

Related Topic