Activity Forums Salesforce® Discussions How to use encodeURI in Salesforce Apex?

  • Abhinav

    Member
    June 22, 2016 at 11:05 am

    Hi Bhavesh,

    You can use Salesforce EncodingUtil Class urlEncode method to encode your string.

    String encodedString = EncodingUtil.URLENCODE('bhavesh jogi','UTF-8');

  • Bhavesh

    Member
    June 22, 2016 at 11:14 am

    Hello Abhinav,

     

    I used this yesterday but actually result of this EncodingUtil.URLENCODE  is like 'bhavesh+jogi'

    Actually, result should be 'bhavesh%20jogi'.

    Let me know if other solution is in Salesforce.

  • Abhinav

    Member
    June 22, 2016 at 12:00 pm

    In, URLENCODE Space characters are replaced by `+'

    You have to replace it :-

    String encodedString = EncodingUtil.URLENCODE('bhavesh jogi','UTF-8').replace('+', '%20');

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos