Is there any way to handle a & in a params being sent in the URL of a restAPI call. So that the system doesn't think this the end and start of a different params? The URL being sent is below:

/services/apexrest/task?branchId=60521::BAC::London::Finance, Temp & PQ

When viewing the call in the debug log the & PQ is missing the branchId

enter image description here

If you need any further information, please let me know.

1 Answer 1


Yes, you have to escape it, basically you use the method escapeHtml4() of the class String.

String s1 = 
String s2 = 
// Output:
// &quot;&lt;Mom&amp;Dad&gt;&quot;

You can refer to this similar question.

You can find useful the similar concept in another language, for example in Javascript

  • 4
    I might suggest EncodingUtil.urlEncode() instead, but the gist of it is correct (the characters need to be encoded/escaped)
    – Derek F
    Nov 30, 2020 at 19:35
  • 1
    Thanks for your answers. Its pointed me in the right direction Nov 30, 2020 at 21:19

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.