Working with records whose names include special characters

Record names in Financials may include special characters. For example, there may be companies with names like A & B or John’s Depot.

When working with such records via the Salesforce API, in your HTTP requests you need either to escape special characters with a backslash (\) or replace them with so called URL escape characters. If you don’t do that, you’ll get a malformed query error.

For example, to retrieve a company whose name is John’s Depot, you need to escape the single quote in the company with a backslash:

GET https://mydomain.salesforce.com/services/data/v41.0/queryAll?q=SELECT Id, Name FROM s2cor__Sage_COR_Company__c WHERE Name='John\'s Depot'

Sample response:

{
    "totalSize": 1,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "s2cor__Sage_COR_Company__c",
                "url": "/services/data/v41.0/sobjects/s2cor__Sage_COR_Company__c/a1G1t00000014ikEAA"
            },
            "Id": "a1G1t00000014ikEAA",
            "Name": "John's Depot"
        }
    ]
}

To retrieve a company whose name is A & B, you’ll need to replace the ampersand (&) with the corresponding URL escape character, which is %26:

GET https://mydomain.salesforce.com/services/data/v41.0/queryAll?q=SELECT Id, Name FROM s2cor__Sage_COR_Company__c WHERE Name=’A %26 B'

Sample response:

{
    "totalSize": 1,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "s2cor__Sage_COR_Company__c",
                "url": "/services/data/v41.0/sobjects/s2cor__Sage_COR_Company__c/a1G1t00000014iuEAA"
            },
            "Id": "a1G1t00000014iuEAA",
            "Name": "A & B"
        }
    ]
}

The following table lists some common special characters and the corresponding URL escape characters:

Special character URL escape character
# %23
$ %24
% %25
& %26
@ %40
` %60
/ %2F
: %3A
; %3B
< %3C
= %3D
> %3E
? %3F
[ %5B
\ %5C
] %5D
^ %5E
{ %7B
| %7C
} %7D
~ %7E
%22
%27
+ %2B
, %2C
Anonymous