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
Naveen JainNaveen Jain 

Compilation error in Apex - Invalid Class RestRequest - while creating REST API

I have this very simple class that I am trying to create and am getting compilation error.

 

Can someone help resolve this?

 

Error: Compile Error: Invalid class: restrequest at line 6 column 32 

 

/* test*/
@RestResource(urlMapping='/Account/*')
global with sharing class AccountRestSvc {

  @HttpGet
  global static Account doGet (RestRequest req, RestResponse res) {
    return [select id, name from account limit 1];  
  }

}

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

RestRequest is part of the Apex Rest API.  A couple of things to check

 

(1) Is your org enabled for Apex Rest - I believe this is still in pilot.

(2) Is your code at the correct API level - I'd expect it to need API 22 as this was introduced in summer 11.

All Answers

Ankit AroraAnkit Arora

The error says your class "RestRequest" is invalid now and you need to recompile it, means edit and save it again. Then this error will be resolved.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

bob_buzzardbob_buzzard

RestRequest is part of the Apex Rest API.  A couple of things to check

 

(1) Is your org enabled for Apex Rest - I believe this is still in pilot.

(2) Is your code at the correct API level - I'd expect it to need API 22 as this was introduced in summer 11.

This was selected as the best answer
Naveen JainNaveen Jain

Working with Support to enable this option.

 

Thanks