EDIT – I've updated title and added answer, there are issues using . in URLs for Salesforce REST
I am writing a REST web service in salesforce to return information about accounts.
I am finding that when I use an email address in the URI, I get a Salesforce error.
Here's some code to show the problem
@RestResource(urlMapping = '/showaccount/*')
global without sharing class showAccount {
@HttpGet
global static String doGet() {
String uriRequested = RestContext.request.requestURI;
System.debug(uriRequested);
return uriRequested;
}
}
If I go ahead and make a rest call to the following URL:
/services/apexrest/showaccount/this_sort_of_key_is_fine
then the response is as expected, http code 200 and body of "/showaccount/this_sort_of_key_is_fine"
However if I call the URL and the last part looks like an email address, as follows
/services/apexrest/showaccount/customer@busy.com
then my rest code isn't executed by Salesforce and the response is http code 404 with a body of: [{ "errorCode": "NOT_FOUND", "message": "The requested resource does not exist" }]
The question how-does-salesforce-handle-wildcards-in-a-rest-urlmapping-property is interesting as it seems to me that my problem is also related to how Salesforce is finding the correct rest class from the supplied URL.
I have also found that if I change the urlmapping of the class to /showaccount/*/* then the class is successfully called when I use /showaccount/customer@busy.com/ (but note the trailing / which I would like to avoid).
So my question is
- is there a way to make this work so that I can use a call like
/showaccount/[email address] and get a response? - does this sound like a Salesforce bug?
Best Answer
I have had a response from Salesforce support and I've also done a bit more experimenting. The problem comes from the . character not the @ and the word from salesforce was "using REST API .json and ,xml extension so there is a rule in load balancer that uses regex depending upon how many characters added after dot."
So the following examples are illustrative:
Looks like with the way that the regex is implemented you should be very careful if the URL can include the period character and terminate the URL with a / if possible