0

Hi guys do u have any Idea how to call the value of picklist in Case for example using Schema.PicklistEntry. Do I need to attach the Schema.PicklistEntry in a String?

if(toAddresses.size()>0){ System.debug('Inside the to Addresses.size'); newCase.Description = email.plainTextBody; newCase.Subject = email.subject; newCase.Status= 'New';

}

2
  • Can you be more specific, please?
    – Mahmood
    Commented Sep 26, 2017 at 19:04
  • newCase.Status='New' is only a static and not a good practice of getting a picklist value I want to get It via Schema.PickListEntry Sorry about for not being specific Commented Sep 26, 2017 at 19:08

1 Answer 1

0

Looks like you're writing an inbound email handler?

For your particular scenario I'd say "don't:". Why you need to specify the status? Most likely the default is already "New" (if administrator set "Closed" as default for whatever bizarre reason - ask him about it instead of trying to work around his decision). The less code you have, the easier it gets ;) Respect the defaults, don't surprise the users, don't make them think.

A more generic answer... Something like this?

Schema.DescribeFieldResult f = Case.Status.getDescribe();
for(Schema.PicklistEntry pe : f.getPicklistValues()){
    if(pe.isActive() && pe.isDefaultValue()){
        c.Status = pe.getValue();
        break;
    }
}
1
  • I want to get the value of the picklist for example if the picklist got a value of 'New' , 'Med' and 'Closed'. I want to get it on the picklist dynamically instead of using newCase.Status='New' I want to use newCase.Status=Schema.PicklistEntry but I am having a hard time getting the value of picklist dynamically Commented Sep 27, 2017 at 17:48

You must log in to answer this question.

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