I am having a webserve static method and need to define a function which returns a string inside that webservice method

global class ABC 
   webservice static string XYZ()
    // need to define that method inside XYZ method

But while adding public string method inside webservice method . I am getting an error as Unexpected token 'public'.Please let me know how can I add a method inside webservice method

1 Answer 1


you can't declare method inside of the method. Do it on the same level, as webservice method.

global class ABC {
    webservice static string XYZ(){
        // calling EFG method

    //private method on the same level as webservice
    private static void EFG(){
  • Thanks a lot for the help Oleksandr . Just one doubt ,but what if that method has scope which is just needed within the webservice method .
    – user75937
    Jan 6, 2020 at 12:06
  • You can pass what needed as params if the method EFG Jan 6, 2020 at 12:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .