3

I am using if else loop in my method, facing this error while compilation.

Expecting right curly bracket, found 'else'

Here is my method:

public List<SelectOption> actionTypeOptions {
    get {
      if (actionTypeOptions == null) {
        actionTypeOptions = new List<SelectOption>{new SelectOption('', '--None--')};
        }

        if(division == 'val1' && subDivision == 'val2'){
        for (Action_Type_Options__c a : Action_Type_Options__c.getall().values()) {
          actionTypeOptions.add(new SelectOption(a.Value__c, a.Name));
        }
        else{
        for (Action_Type_Options__c a : Action_Type_Options__c.getall().values()) {
          actionTypeOptions.add(new SelectOption(a.Value1__c, a.Name));

            }
            }

      }
      actionTypeOptions.sort();

      return actionTypeOptions;
    } 
    set;
  } 
1
  • 2
    This issue can be avoided by using indentation consistently. I suggest adopting a style guide such as Google's Java Style Guide.
    – Rob
    Aug 16, 2016 at 13:20

2 Answers 2

2
if(division == 'Honda' && subDivision == 'Campaign'){
        for (Action_Type_Options__c a : Action_Type_Options__c.getall().values()) {
          actionTypeOptions.add(new SelectOption(a.Value__c, a.Name));
        }
}

You're missing to close one bracket here. Before the else.

1

You're missing the closing bracket after your loop inside the if statement.

You need:

if (condition)
{
    for (...)
    {
        ...
    }
} // MISSING
else
{
    for (...)
    {
        ...
    }
}

You must log in to answer this question.

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