[SalesForce] REST Resource class not working

I'm trying to learn REST and for this I tried to create a rest service class with the aim of retrieving accounts. Now whenever I'm executing this in workbench this is showing response code 404. Can someone help me in finding out what wrong I'm doing?
Here's the code I did–>

RestResource(urlMapping='/account/*')

global with sharing class AccountRestService {

@HttpGet
global static Account doGet() {

    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;

    String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
    Account results = [SELECT Name,Phone,Id FROM Account where External_Id__c =:accountId];
    return results;
 }
}

In workbench i chose GET method and gave this /services/apexrest/v34.0/account/1200. I have created a custom field External_Id__c as Text type .

Best Answer

When you define your own service class:

The URL mapping is relative to https://instance.salesforce.com/services/apexrest/.

So in your case try:

https://instance.salesforce.com/services/apexrest/account/1200

You can introduce your own versioning in the @RestResource definition if you want to.

Related Topic