Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

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

rec.lookupField__c == null;         // OR
rec.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 blankHow to check in Apex if a Text field is blank. I posted this anyway because I need confirmation on the approach specifically for a lookup field. The linked 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.

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

rec.lookupField__c == null;         // OR
rec.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. I posted this anyway because I need confirmation on the approach specifically for a lookup field. The linked 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.

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

rec.lookupField__c == null;         // OR
rec.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. I posted this anyway because I need confirmation on the approach specifically for a lookup field. The linked 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.

deleted 36 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

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

rec.lookupField__c == nullnull;         // OR

OR

rec.lookupField__c == '''';           // OR 

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 ,. I posted this anyway because I need confirmation on the approach specifically for a lookup field. The mentioned SFSElinked 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.

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.

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

rec.lookupField__c == null;         // OR
rec.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. I posted this anyway because I need confirmation on the approach specifically for a lookup field. The linked 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.

Source Link
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.