1

I have a simple piece of code but I'm getting an error:

Compile Error: Method must define a body at line 28 column 25.

I'm new to Salesforce development and can't figure out this error

global with sharing class MyController {

    public String allSectors {
        get {
            List<String> sectors = GetSectors();
            allSectors = '';
            for (String i : sectors)
            {
                if (allSectors == '')
                {
                    allSectors = i;
                }
                else
                {
                    allSectors += ',' + i;
                }
            }
            return allSectors;
        }
        set;
    }

    public MyController()
    {
        //do something
    }

    public List<string> GetSectors();
    {
        List<String> sectorList = new List<String>();
        //populate list
        return sectorList;
    }

    @RemoteAction
    global static String GetSectorDetails(string sectorName)
    {       
        return 'something';
    }
}

Any help will be highly appreciated.

1 Answer 1

3

Remove ";" from

public List GetSectors();
. You can't have ";" for method names.

global with sharing class MyController {

    public String allSectors {
        get {
            List sectors = GetSectors();
            allSectors = '';
            for (String i : sectors)
            {
                if (allSectors == '')
                {
                    allSectors = i;
                }
                else
                {
                    allSectors += ',' + i;
                }
            }
            return allSectors;
        }
        set;
    }

    public MyController()
    {
        //do something
    }

    public List GetSectors()
    {
        List sectorList = new List();
        //populate list
        return sectorList;
    }

    @RemoteAction
    global static String GetSectorDetails(string sectorName)
    {       
        return 'something';
    }
}
1
  • oh crap, sometimes silly errors are over looked, thanks mate :)
    – user569925
    Nov 12, 2015 at 16:39

You must log in to answer this question.

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