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

Can someone help me get this sosl escape map working?
I need to do a query on a long text area field that contains special characters, "-" "(" ")". I found an escape map that seems to have come from the Salesforce Developer site, but it won't save. Can someone help me figure out how to fix it? I changed all of the double quotes to single quotes and that didn't work.
Thanks
https://salesforce.stackexchange.com/questions/254017/sosl-query-with-special-characters
Thanks
https://salesforce.stackexchange.com/questions/254017/sosl-query-with-special-characters
public class StringUtils { /** * Reserved characters which need to be escaped in SOSL * https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm */ public static final CharSequenceTranslator ESCAPE_SOSL; static { final Map<CharSequence, CharSequence> escapeSoslMap = new HashMap<>(); escapeSoslMap.put("?", "\\?"); escapeSoslMap.put("&", "\\&"); escapeSoslMap.put("|", "\\|"); escapeSoslMap.put("!", "\\!"); escapeSoslMap.put("{", "\\{"); escapeSoslMap.put("}", "\\}"); escapeSoslMap.put("[", "\\["); escapeSoslMap.put("]", "\\]"); escapeSoslMap.put("(", "\\("); escapeSoslMap.put(")", "\\)"); escapeSoslMap.put("^", "\\^"); escapeSoslMap.put("~", "\\~"); escapeSoslMap.put("*", "\\*"); escapeSoslMap.put(":", "\\:"); escapeSoslMap.put("\\", "\\\\"); escapeSoslMap.put("\"", "\\\""); escapeSoslMap.put("'", "\\'"); escapeSoslMap.put("+", "\\+"); escapeSoslMap.put("-", "\\-"); ESCAPE_SOSL = new AggregateTranslator(new LookupTranslator(Collections.unmodifiableMap(escapeSoslMap))); } /** * Escape SOSL reserved characters * https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm */ public static final String escapeSosl(final String input) { return ESCAPE_SOSL.translate(input); } }