I have been wondering why a string of this form

ERROR on search state=ERROR error=[{"message":"System.QueryException: sObject type..."}]

displays like this:

ERROR on search state=ERROR error=[]

when used as the message of a e.force:showToast.

Checking the documentation, I see that the messageTemplate parameter supports the substitution of values via {0}, {1} etc and suspect that the same processing is being applied to the message i.e. the content between the curly brackets is assumed to be a numbered parameter to be substituted and so is discarded.

Assuming that, my question is how to escape the curly brackets. This Java MessageFormat escaping doesn't work:

m = m.replace('{', '\'{\'').replace('}', '\'}\'');

and neither do these:

m = m.replace('{', '\\{').replace('}', '\\}');
m = m.replace('{', '\{').replace('}', '\}');

Anyone found escaping that does work here?


I'm discarding them for now:

m = m.replace('{', '').replace('}', '')
  • Log a case with Salesforce; this is not expected behavior. I have a workaround for you, though. – sfdcfox Apr 3 '18 at 17:08

As far as I can tell, you have to literally use templating to get them to appear correctly:

    init: function(component, event, helper) {
                    message:"hello world",
                    messageTemplate:"{0}hello world{1}",
                    messageTemplateData: ["{","}"]})
  • Very sneaky ... – Keith C Apr 3 '18 at 17:12

Using sfdcfox's work around, this puts in the numbered placeholders:

m = m.replace('{', '_PLACE_KEEPER_').replace('}', '{1}').replace('_PLACE_KEEPER_', '{0}');

and note that you have to supply a non-empty message that the messageTemplate:

Overwrites message string with the specified message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.