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
sree sfdcsree sfdc 

Compile Error: unexpected token: 'global'

hi floks ,

how to reslove this error pls help me

Compile Error: unexpected token: 'global'
Best Answer chosen by sree sfdc
Dev.AshishDev.Ashish
Sree,

You are defining global class Records in method doGet(), simply this is not allowed. You have to include your inncer class "Records" directly one level into class "MyRestResource. So could will be like ... 
@RestResource(urlMapping='/fetchAccounts/*')
global with sharing class MyRestResource {

    @HttpGet
    global static List<Records> doGet() {


    }

    global class Records
    {
      
    }  

}



All Answers

Dev.AshishDev.Ashish
This error could occure due to 2 reasons 
1) If you define 2 classes in one file on same level, like below 
global class A{
}
global class B{
}
2) If you define classes more then one level deep, like below.
global class A{

  global class B{

    global class C{
    }

  }

}



sree sfdcsree sfdc
hi ashish dev
i m wrote code same pattern but i got the error  Compile Error: unexpected token: 'global'
this is my  code;
@RestResource(urlMapping='/fetchAccounts/*')
global with sharing class MyRestResource {

    @HttpGet
    global static List<Records> doGet() {


    global class Records
    {
      
    }  
}
}
Dev.AshishDev.Ashish
Sree,

You are defining global class Records in method doGet(), simply this is not allowed. You have to include your inncer class "Records" directly one level into class "MyRestResource. So could will be like ... 
@RestResource(urlMapping='/fetchAccounts/*')
global with sharing class MyRestResource {

    @HttpGet
    global static List<Records> doGet() {


    }

    global class Records
    {
      
    }  

}



This was selected as the best answer