5

I have an issue in Getting url parameters.Since i have german alphabets as values for parameters some of the characters are not decoded properly .

my_vorname=Example_���my_name=Example_��my_strasse=Example_��dc_plz=100 this is how i get the parameters from salesforce.But from the client side i am getting proper values.

How to solve this problem?

3
  • Can you please share the relevant code as it is possible that issue is in it?
    – IvanR
    Commented Dec 15, 2014 at 11:50
  • The URL is not controlled by salesforce code .A client application sends the URL along with their parameters to salesforce.So when i try to get the URL all values are malformed. Commented Dec 15, 2014 at 14:07
  • Do you know which encoding client application uses? If not, you could try using Daniel Ballinger's code snippet to try and decode string you get from client app using several common encodings and see if any of them produce correct output.
    – IvanR
    Commented Dec 15, 2014 at 14:18

2 Answers 2

3
+25

When the German umlaut characters are sent on the query string they should be URL encoded for either UTF-8 or ISO-8859-1. Then, as per Uwe's answer you can specify the encodingScheme with the second parameter in the urlDecode and urlEncode methods.

E.g. UTF-8 encoding where ä will be encoded as %C3%A4

string input = 'my_vorname=Example_ämy_name=Example_ämy_strasse=Example_ädc_plz=100';
String urlencoded = EncodingUtil.urlEncode(input, 'UTF-8');
System.debug(urlencoded);
string decoded = EncodingUtil.urlDecode(urlencoded, 'UTF-8');
System.debug(decoded);
System.assertEquals(input, decoded);

Output: UTF-8 German umlaut encoding on query string

E.g. ISO-8859-1 encoding where ä will be encoded as %E4

string input = 'my_vorname=Example_ämy_name=Example_ämy_strasse=Example_ädc_plz=100';
String urlencoded = EncodingUtil.urlEncode(input, 'ISO-8859-1');
System.debug(urlencoded);
string decoded = EncodingUtil.urlDecode(urlencoded, 'ISO-8859-1');
System.debug(decoded);
System.assertEquals(input, decoded);

Output: enter image description here

You could also specify UTF-16, which gives you and encoded value of %FE%FF%00%E4 for ä.


What encoding were you using when you asked the question? In my version of chrome it appears as:

enter image description here

Firefox was the same and IE had square placeholder characters.

4
  • I dont have issue in storing the german characters in string and decoding it .The issue is when you pass the german characters in URL and then try to decode you will not get the correct decoded value. I have raised this issue to salesforce support. Commented Dec 12, 2014 at 14:33
  • @ManojChandran I think you have an issue with encoding the German characters in the query string. My examples used strings to show how the values could be encoded and then decoded using various encoding schemes. The query string is exactly that, a string that is interpreted from the end of the URL. Can you add a screenshot of how the characters appear for you? Commented Dec 13, 2014 at 23:48
  • shall we discuss in private chat Commented Dec 15, 2014 at 6:45
  • @ManojChandran I'm not sure I'll be able to catch you in a private chat. Can you add a screenshot of the characters you are encoding? Commented Dec 16, 2014 at 1:03
1

If you want to do it with apex, have a look at the EncodingUtils class, there are two functions

  • urlDecode(String, String)
  • urlEncode(String, String)

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_encodingUtil.htm

You can also do it with javascript, if you like.

1
  • I tried this but its not working Commented Dec 2, 2014 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .