function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pjaenick.ax736pjaenick.ax736 

Lookup field Comparison logic / null check

I'd like to detect if a lookup to an object compare a lookup field between "recordA" and "recordB".

 

Is there a more streamlined / shorthand logic approach other than :

  1.  Checking if A is Null and B is not Null OR

  2.  Checking if B is Null and A is not Null OR

  3.  A and B are both not Null and are different?

 

T-e-d-i-u-m !

 

Thanks,

Pete

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

According to the docs, the equality (==) and inequality (!=) operators can take nulls on the left or right hand side,  so you should simply be able to use:

 

if (RecordA.Lookup__c!=RecordB.Lookup__c)

 

All Answers

bob_buzzardbob_buzzard

According to the docs, the equality (==) and inequality (!=) operators can take nulls on the left or right hand side,  so you should simply be able to use:

 

if (RecordA.Lookup__c!=RecordB.Lookup__c)

 

This was selected as the best answer
pjaenick.ax736pjaenick.ax736

Really !?  Wow.. my bad then.  Been doing it the hard-way all along.

 

I guess my 'reflex memory' has beed trained to avoid "attempt to dereference a null object" issues at all costs.

 

Thank You !!