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;
  } 
  • 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 '16 at 13:20
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.

| improve this answer | |
1

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

You need:

if (condition)
{
    for (...)
    {
        ...
    }
} // MISSING
else
{
    for (...)
    {
        ...
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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