Print this page

Encoded URL parameters are automatically decoded when retrieving variables from the URL

Knowledge Article Number 000188563
Description When attempting to pass in URL-encoded variables via a URL (e.g., %2B for + sign), it's important to note that these variables will be automatically decoded when they're retrieved from the URL. That way, developers can keep track of precisely which decoded values their corresponding records should have in Apex. Corresponding records in Salesforce should never have the encoded value in their record values, as this won't match up with what the controller retrieves from a page's parameters. 
Resolution Accessing encoded variables (e.g., %2B) via a URL (e.g., means that the variable will be auto-decoded when retrieved. If the aforementioned "param" variable's value is used to generate a SOQL query, it's important to note that this will be used as a + symbol in any variable assignments, so if you have a SOQL query using this variable, it will not maintain the encoded value when retrieved from the URL. This is by design, and it should be accounted for in the variable retrieval. 

Here is an example page:
<apex:page standardController="TestObject__c" extensions="urlParam">
  <apex:outputtext>Test parameter passed in: {!urlParameter}</apex:outputtext>
public class urlParam {
    private String urlParameter; //{ get; set; }
    public urlParam(ApexPages.StandardController controller) {
        urlParameter = String.valueOf(ApexPages.currentPage().getParameters().get('param'));
    public String getUrlParameter() {
        return urlParameter;

This will print the following on a page: Test parameter passed in: +


For adding parameters, values are added without the need to encode values.
For example, using ApexPages.currentPage().getParameters().put('test', '+'), followed by String param = ApexPages.currentPage().getParameters().get('test'); will set param equal to "+". 


promote demote