I have two Apex Rest Webservice Rest1 & Rest2.

Rest1 webservice Apex class has annotation @RestResource(urlMapping='/ApexRest/')

Rest2 webservice Apex class has annotation @RestResource(urlMapping='/ApexRest/*') which is saved last.

But when I tried to call the Apex Rest webservice using url url/service/apexrest/ApexRest it calls Rest1 not Rest 2 which is last saved. So I am getting confused, Is salesforce documentation is right?

An extract from Page No: 255 Force.com Apex Code Developer's Guide V34.0 summer'15 documentation:

The URL patterns URLpattern and URLpattern /* match the same URL. If one class has a urlMapping of URLpattern and another class has a urlMapping of URLpattern /*, a REST request for this URL pattern resolves to the class that was saved last.


The base URL and the urlMapping value form the URI that the client sends in a REST request. In this case, the URL mapping contains the asterisk wildcard character, which means that the resource URI can contain any value after /Apexrest/.

In your web service you are using the url(url/service/apexrest/ApexRest), which by defaults calls the rest1. To avoid confusions have proper url mapping values for both rest 1 and rest 2, like @RestResource(urlMapping='/Rest1/*')

  • I can choose the option to change the url mapping name so that there is no more confusion. But I want to know the reason why this is not as documented in salesforce or may be I am wrong here?
    – Ajay Gupta
    Jul 20 '15 at 15:08
  • If you want to call Rest you may need to use url/service/apexrest/ApexRest. For calling Rest 2 you may need to use url/service/apexrest/ApexRest/. The '/' at the end determines to call Rest2 or not. I am not 100% sure, but this what the I understood from documentation
    – Goki
    Jul 21 '15 at 4:19
  • Please look at the question again and tell me which will execute first Rest1 or Rest2? Rest1 url is url/service/apexrest/ApexRest/. For calling Rest 2 url is url/service/apexrest/ApexRest/* .
    – Ajay Gupta
    Aug 22 '15 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.