You need to sign in to do that
Don't have an account?
Saroja Murugan
Class Error
Hi All,
Hope everybody doing well,
I have studied about enum datatype and trying to understand it by using the below code.
But it throw me an error while saving the apex class MyExample.
Please let me know how to resolve this?
Season:
public enum Season {
WINTER,SPRING,SUMMER,FALL
}
Month:
public enum Month {
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
}
MyExample:
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;
}
}
Thanks,
Hope everybody doing well,
I have studied about enum datatype and trying to understand it by using the below code.
But it throw me an error while saving the apex class MyExample.
Please let me know how to resolve this?
Season:
public enum Season {
WINTER,SPRING,SUMMER,FALL
}
Month:
public enum Month {
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
}
MyExample:
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;
}
}
Thanks,
you need to define the type of list, following code may help you:
Cheers,
Dev
All Answers
you need to define the type of list, following code may help you:
Cheers,
Dev
The class saved but how to execute this code in Developer Console?
I tried like below
System.debug(Season.WINTER);
MyExample obj = new MyExample();
System.debug(obj.seasonMonths(Season.WINTER));
Thank you so much for all your help.
In the logs, you can find something similar to these lines: if you need reference to how to anaylze logs, please refer this:
https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/developer_console/units/developer_console_logs
Cheers,
Dev