2

How could we pass an get a value from an enum inside a method.

According to the below code snippet, how could I pass the value of the parameter to severity__c in Note__c instance??

enum severity {LOW, MEDIUM, HIGH, CRITICAL}
public static Note__c create(String head, String body, severity sev) {
    return new Note__c(
        Head__c = ntype,
        Body__c = body,
        severity__c = severity.valueOf(sev) ??
  ); 
}

Thanks

1 Answer 1

2

It looks like you're after the name() method.

name

Returns the name of the Enum item as a String.

eg.

enum severity {LOW, MEDIUM, HIGH, CRITICAL}
public static Note__c create(String head, String body, severity sev) {
    return new Note__c(
        Head__c = ntype,
        Body__c = body,
        severity__c = sev.name()
  ); 
}

You must log in to answer this question.

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