+ Start a Discussion
Equipe VREquipe VR 

Error URL mapping Apex Rest API

Hi all,

I'm making a custom Rest API and having some problems with endpoints mapping.
I had a class named RestResource_Opportunities, with mapping @RestResource(urlMapping='/contas/*/oportunidades');
And a class named RestResource_OpportunityId, with mapping  @RestResource(urlMapping='/contas/*/oportunidades/*').

When I compile the Opportunities class, the both endpoints maps to OpportunityId class.
When I compile the OpportunityId class, the both endpoints maps to Opportunities class.

This behavior also happens with /contas/*/contatos and /contas/*/contatos/* endpoints.

I don't know why this happens, since the mappings are differents... Anyone can help?

Om PrakashOm Prakash
Hi Equipe,
Currently only difference between both url are  suffix  '/*' 
I suggest to use different prefix maping url for both classes. (like /contas/*/oportunidades in first class and /contas/*/oportunidadesId/* in second class)

Your both urlMapping seems different so you don't have duplicate urlMapping error during saving or compiling the class.
But during callling rest resource both urlMapping are behaving simillar and you are getting unexpected result because the rules for mapping URLs are:
An exact match always wins.
If no exact match is found, find all the patterns with wildcards that match, and then select the longest (by string length) of those.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_rest_resource.htm