1

below is my code Created a wrapper class like below

public class ResponseWrapper{
    public list<Account> lstaccounts;
    public boolean isError ;
    public string errorCode;
    public integer statusCode;
       public ResponseWrapper(){
         lstaccounts = new list<Account>();
         isError= false;
    }
}


 @getMethod

@RestResource(urlMapping='/accounts/*')
 global with sharing class AccountRestService {
 @HttpGet
 global static ResponseWrapper getAccounts() {
     ResponseWrapper resWrap = new ResponseWrapper();
     List<Account> accounts;
     try {
         accounts = [SELECT Id, Name FROM Account];
         res.lstaccounts = accounts;
     } catch (Exception e) {
         RestResponse res = RestContext.response;
         resWrap.isError = true;
         res.responseBody = Blob.valueOf(e.getMessage()) = resWrap.errorCode;
         res.statusCode = 500 = resWrap.statusCode;
     }
     return resWrap;
   }
 }

but iam getting the below Error: Compile Error: global methods do not support return type of ResponseWrapper at line 4 column 31

Please check and suggest on this whats the exact mistake i did.

Thanks & Regards. Vamsi Krishna.

1

When you define a global method, your return type must also be global. Change your access modifier on the ResponseWrapper class from public to global.

Not the answer you're looking for? Browse other questions tagged or ask your own question.