+ Start a Discussion
Ghanshyam Kumar 9Ghanshyam Kumar 9 

Getting space for + sign in apex while reading value from URL

We have a requirement where we are encrypting Salesforce ID value using Crypto class method. Crypto.encryptWithManagedIV('AES128', key, data);

But it generates a key which contains + sign and when we read this value in apex we get space for that + sign.

We tried EncodingUtil.urlDecode and EncodingUtil.urlEncode. In that case + sign is getting converted into %2B and again we get space for that in the apex.

For Ex -

Encoded value in URL gAbH0FIEK5l2m8wVKTV+p4R5QLay2D9jZ2BgsyQ3mJ1/9puMMIne6y5P6i3ZRidl

Encoded value in Apex

gAbH0FIEK5l2m8wVKTV p4R5QLay2D9jZ2BgsyQ3mJ1/9puMMIne6y5P6i3ZRidl

can someone please suggest how to handle the situation?

We can handle spaces by replacing it with + sign. But I am not sure if it will throw an error for any specific characters/case.
Best Answer chosen by Ghanshyam Kumar 9
NagendraNagendra (Salesforce Developers) 
Hi Kumar,

Convert the string to URL encode
Which will replace it to
Now in class simply get it from apex using 
apexpages.currentpage().getparameters().get('parameter Name');and use it you will get expected output.
User-added image
Hope this resolves the issue.

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.