Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

RestResource Annotation

The @RestResource annotation is used at the class level and enables you to expose an Apex class as a REST resource.

Some considerations when using this annotation:
  • The URL mapping is relative to https://instance.salesforce.com/services/apexrest/.
  • The URL mapping can contain a wildcard (*).
  • The URL mapping is case-sensitive. For example, a URL mapping for my_url matches a REST resource containing my_url and not My_Url.
  • To use this annotation, your Apex class must be defined as global.

URL Guidelines

URL path mappings are as follows:

  • The path must begin with a forward slash (/).
  • The path can be up to 255 characters long.
  • A wildcard (*) that appears in a path must be preceded by a forward slash (/). Additionally, unless the wildcard is the last character in the path, it must be followed by a forward slash (/).

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.
  • If no wildcard match is found, an HTTP response status code 404 is returned.

The URL for a namespaced class contains the namespace. For example, if your class is in namespace abc and the class is mapped to your_url, then the API URL is modified as follows: https://instance.salesforce.com/services/apexrest/abc/your_url/. In the case of a URL collision, the namespaced class is always used.