Skip to main content
1 of 3
Prajith
  • 1.6k
  • 1
  • 18
  • 40

Check lookup field is null in apex

What is the best approach to check if a lookup field is null in apex? Is it:

lookupField__c == null

OR

lookupField__c == ''

OR

String.isBlank(rec.lookupField__c )

I apologize if this is the same as How to check in Apex if a Text field is blank , posted this anyway because need confirmation on the approach specifically for a lookup field. The mentioned SFSE question talks only about text field. I am not sure if it is completely safe to consider a lookup field as a text field in this scenario.

Please let me know your thoughts. Thanks in advance.

Prajith
  • 1.6k
  • 1
  • 18
  • 40