Salesforce Apex enum Example

crate a class season,month,MyExample bellow like this
public enum Season {
WINTER,SPRING,SUMMER,FALL
}

public enum Month {
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
}

public class MyExample {
public List seasonMonths(Season s)
{

List listMonths = new List();

if(s==season.WINTER)
{
listMonths.add(Month.DEC);
listMonths.add(Month.JAN);
listMonths.add(Month.FEB);

}
else if(s==season.SPRING)
{
listMonths.add(Month.MAR);
listMonths.add(Month.APR);
listMonths.add(Month.MAY);

}
else if(s==season.SUMMER)
{
listMonths.add(Month.JUN);
listMonths.add(Month.JUL);
listMonths.add(Month.AUG);
}
else if(s==season.FALL)
{
listMonths.add(Month.SEP);
listMonths.add(Month.OCT);
listMonths.add(Month.NOV);
}

return listMonths;
}
/*
Steps to execute this code

System.debug(Season.WINTER);
MyExample obj = new MyExample();
System.debug(obj.seasonMonths(Season.WINTER));
*/
}

Leave a Reply