Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/600974999181197312
Source Link
Robert Sösemann
  • 38.6k
  • 30
  • 181
  • 520

How to check in Apex if a Text field is blank

I'm unsure what's the shortest and most robust way to check whether a Text field is blank / empty?

/*1*/ Boolean isBlank = record.txt_Field__c == ''; /*2*/ Boolean isBlank = record.txt_Field__c == null; /*3*/ Boolean isBlank = record.txt_Field__c.trim() == ''; /*4*/ Boolean isBlank = record.txt_Field__c.size() == 0;