We are replacing all the javascript buttons to custom VF buttons. Have used encodeURIComponent methods in Javascript, unable to find the equivalent salesforce method

Have checked EncodingUtil Class in salesforce but that doesn't seem to solve the purpose ?

Input :

 var uri = "http://w3schools.com/my test.asp?name=ståle&car=saab";
    var res = encodeURIComponent(uri);

Output :


Thanks for the help !


Did you check:

String encoded = EncodingUtil.urlEncode(url, 'UTF-8');

Reference: EncodingUtil


String url = 'http://w3schools.com/my test.asp?name=ståle&car=saab';
String encoded = EncodingUtil.urlEncode(url, 'UTF-8');
System.debug(' Encoded URL: '+encoded);


Encoded URL: http%3A%2F%2Fw3schools.com%2Fmy+test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab

| improve this answer | |

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.