Skip to main content
I have created apex rest service and  I am calling it from workbench rest explorer,but I am getting an error

Created the following class 

@RestResource(urlMapping='/Account/Contacts')

global with sharing class AccountManager{

  @HttpGet

   global static Account getAccount(){

      RestRequest request = RestContext.request;

      // grab the caseId from the end of the URL

        String AccountId= request.requestURI.substring(

          request.requestURI.lastIndexOf('/')+1);

        /*Account result =  [SELECT Id,Name,(Select Name from Contacts) FROM Account

                        WHERE Id = :AccountId];  */

          Account result =  [SELECT Id,Name FROM Account WHERE Id = :AccountId];               

        return result;

   }

 

}

And then when

I am giving the url as /services/apexrest//Account/Contacts/<AccountID>

Error is: Service not found at: /services/apexrest/Account/Contacts/001......

Can some body please help me,why is this error or  with the steps to followed..

Thanks in Advance... 
10 Antworten
  1. 13. Apr. 2016, 18:32
    Please check below post for step by step process with screen shot.

    1) http://amitsalesforce.blogspot.com/2016/04/rest-api-in-salesforce-execute-rest-api.html

    Do minar change your code like below :-

    @RestResource(urlMapping='/Account/Contacts/*')

    global with sharing class AccountManager

    {

    @HttpGet

    global static Account getAccount()

    {

    RestRequest request = RestContext.request;

    String AccountId= request.requestURI.substring( request.requestURI.lastIndexOf('/')+1);

    Account result = [SELECT Id,Name FROM Account WHERE Id = :AccountId];

    return result;

    }

    }

    I just added * in your URL

    Your URL should be :- /services/apexrest/Account/Contacts/<AccountID>

    Method :- Get

    Ley us know if this will help you

    Thanks

    Amit Chaudhary
0/9000