function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
divya manohardivya manohar 

rest resource issue

@RestResource(urlMapping='/myrest2/*')
global with sharing class Rest_Class2
{
   @HTTPGet
   global static Account[] doGet()
   {
      RestRequest req = RestContext.request;

      RestResponse res = RestContext.response;
      
      String currentIndustry=req.requestURI.substring(req.requestURI.lastIndexof('/')+1);
      
      Account[] acts=new Account[]{};
      
      if (currentIndustry=='all')
      
         acts=[select Name,Industry from account where Industry=:currentIndustry];
      
      else
      
          acts=[select Name from account where Industry=:currentIndustry];
         
      return acts;
   } 
   
}
Hi friends

I have written a rest resource where I want to display all account where Industry='Energy'. when I test this is work bench it is showing error as 
Service not found at: /services/apexrest/industry/enerygy

If it do as       /services/apexrest/industry/all    then it will show all accounts
But either way its not showing records.
Pls guide me.

divya
 
Best Answer chosen by divya manohar
Prem Anandh 1Prem Anandh 1
Hi Divya, 

 /services/apexrest/industry/enerygy - Here is the mistake. Please refer below code for calling the @RestGet Annontation. 
  • /services/apexrest/myrest2/Agriculture
  • myrest2 - its service name 
  • Agriculture -  industry type

If your service is packaged please add your package namespace as I mentioned below:
  • /services/apexrest/namespace/myrest2/Agriculture

Thanks,
Prem Anandh
 

All Answers

Abhishek Vishwakarma 5Abhishek Vishwakarma 5
Hi Divya,

Might be your Org has a namespace and this you are missing in your Url.
divya manohardivya manohar
Hi abhishek
I went to remote site settings but not sure of https or http.

Thanks
divya
Prem Anandh 1Prem Anandh 1
Hi Divya, 

 /services/apexrest/industry/enerygy - Here is the mistake. Please refer below code for calling the @RestGet Annontation. 
  • /services/apexrest/myrest2/Agriculture
  • myrest2 - its service name 
  • Agriculture -  industry type

If your service is packaged please add your package namespace as I mentioned below:
  • /services/apexrest/namespace/myrest2/Agriculture

Thanks,
Prem Anandh
 
This was selected as the best answer
divya manohardivya manohar
Hi Anandh
Thanks, I did not have to perform remote site setting.
/services/apexrest/myrest2/energy    works

But if I give /services/apexrest/myrest2/all  it doesnt work. Am I missing anything?
Prem Anandh 1Prem Anandh 1

Can you confirm if "all" value is available in Industry picklist? 
If not added please add that value. I don't think if its there already. 

 

divya manohardivya manohar
Hi
I have added  "all" to the industry picklist and its is reflecting when an new account is created.
In workbench I am giving  /services/apexrest/myrest2/All     but no data displayed.

Thanks
divya
Prem Anandh 1Prem Anandh 1
Make sure the UpperCase and Lower Case "All" or "all" or "All". Please pass the correct case. 
divya manohardivya manohar
Thanks
its working