How to encode the special characters for correct URL String using apex in Salesforce?

Sample Code:

String strURL = 'www.test.com?name=#1solutions';
strURL = EncodingUtil.urlEncode(strURL, 'UTF-8');

EncodingUtil.urlEncode() encodes the special characters for correct URL String.

Cheers!!!

2 comments:

  1. how to decode url in salesforce lightning component

    ReplyDelete
    Replies
    1. Check this - http://www.infallibletechie.com/2018/06/how-to-encodedecode-url-in-salesforce.html

      Delete