You need to sign in to do that
Don't have an account?
Nikhil Jaitly 8
Service Not Found : Rest
I have created a simple REST service which fetches the Account Id,Name and the associated Contacts. Whenever I try to reach this web service from Workbench using this URI : services/apexrest/checkCMT/Accounts/0019000001NQXpJ/contacts , it gives the error 'Service Not Found'
where checkCMT is the namespace I am using in my org.
Here is the code that I have written.
@RestResource(urlMapping='/Accounts/<Account_ID>/contacts')
global with sharing class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest request = RestContext.request;
// grab the AccountId from the mid of the URL
String accountId = request.requestURI.substringBetween('Accounts/', '/contacts');
Account result = [SELECT Id,Name, (select Id,Name from Contacts)
FROM Account
WHERE Id = :accountId];
return result;
}
}
where checkCMT is the namespace I am using in my org.
Here is the code that I have written.
@RestResource(urlMapping='/Accounts/<Account_ID>/contacts')
global with sharing class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest request = RestContext.request;
// grab the AccountId from the mid of the URL
String accountId = request.requestURI.substringBetween('Accounts/', '/contacts');
Account result = [SELECT Id,Name, (select Id,Name from Contacts)
FROM Account
WHERE Id = :accountId];
return result;
}
}
1) http://amitsalesforce.blogspot.com/2016/04/rest-api-in-salesforce-execute-rest-api.html
Do minar change your code like below :- Please check below post for similer issue
1) https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BZhiIAG
Your URL should be :- /services/apexrest/Account/<AccountID>/Contacts
Method :- Get
Let us know if this will help you
Thanks
Amit Chaudhary
All Answers
Just replace your rest resource URL with this and then try:
@RestResource(urlMapping='/Account/*/Contacts/')
1) http://amitsalesforce.blogspot.com/2016/04/rest-api-in-salesforce-execute-rest-api.html
Do minar change your code like below :- Please check below post for similer issue
1) https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BZhiIAG
Your URL should be :- /services/apexrest/Account/<AccountID>/Contacts
Method :- Get
Let us know if this will help you
Thanks
Amit Chaudhary
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest request = RestContext.request;
// grab the AccountId from the mid of the URL
String accountId = request.requestURI.substringBetween('Accounts/', '/contacts');
Account result = [SELECT Id,Name, (select Id,Name from Contacts)
FROM Account
WHERE Id = :accountId];
return result;
}
}
Your URL should be :- /services/apexrest/Account/0019000001NQXpJ/Contacts
Method :- Get
No need to NameSpace in URL
Let us know if this will help you
Thanks
Amit Chaudhary
I changed my url in RestResource as : urlMapping='/Accounts/*/contacts' and had to use the namespace to get it working.
So the URI that I used was : /services/apexrest/checkCMT/Accounts/0019000001NQXpJ/contacts
where checkCMT is my namespace.
Thank you very much for your help.
Nikhil
I did try the URI without the namespace as well, but it didn't work.
Anyways, your suggestion on changing the url did the trick. Thanks
Nikhil
Thank you for introducing the namespace, i also added the name space in the url and its working fine.
this is my url : /services/apexrest/Sachin1/AccountManagementService/
"Sachin1" is the namespace i have created in lightning.