1

I am writing a trigger that has an IF clause based off of a field. However, I cannot get it to recognize if that picklist is blank. I have tried:

field.isblank()
string.isblank(field)
field == ''
field == '--None--'
field == NULL

None of these catch when there is no value. Prior to saving the record, the field says 'deleted' if I set it to --none--...but I'm not sure how to check that value within a trigger.

Thank you!

1 Answer 1

6

A picklist is essentially a string. For a string, you want to test using isEmpty() == true. That covers '' and null. If you have a --none-- you want to test against, you'll want to also add that specifically to your conditions if that's an optional value included in your picklist. If so, use a boolean ||.

4
  • I tried "FIELD.ISEMPTY() == TRUE" and "isempty(FIELD) == TRUE" and neither seems to work...maybe something else in my code is weird... Commented Jul 20, 2015 at 16:12
  • Could very well be the case. It's difficult to say with only seeing the brief snippet and not having any more context.
    – crmprogdev
    Commented Jul 20, 2015 at 16:23
  • Yep, I found it. I'm just feeling a bit stupid right now! I was editing my INSERT portion instead of my UPDATE portion. Thanks for the tips, I really appreciate your time! Commented Jul 20, 2015 at 16:29
  • I got the error "Method does not exist or incorrect signature: void isEmpty() from the type String" and used "if (myObject.myPickListField__c != null){...}" Commented Nov 29, 2021 at 16:25

You must log in to answer this question.

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