You need to sign in to do that
Don't have an account?
pcave
Are blank sObject fields an empty string or NULL
I'm writing some apex code that needs to check to see if a contact has an account assigned via the AccountId field. Do I need to check for an empty or null value? as in?
if (c.AccountId != NULL)
or
if (c.Account != '')
Thanks,
Phillip
Use NULL.
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Hi There,
Just FYI .... for String fields, you should use '' check and for number/Id fields, you should use NULL check.
In some cases, you might face some weird issues with such comparisons, the workaround then is to check for both :D
hope this helps!!
Cool_D
Hi There,
Use NULL check for Account like
If you will use Contact.AccountId!='' you will get an error saying Invalid Id.
hope this helps :)
Thanks,
Amit Singh.
Use Null if it is sobject like Account or customObject
if it is Contact.AccountId then it is ID not Sobject reference , in that case you can use String.isBlank(String.valueOf(Contact.Account)) but not generally advicable
c.Account is an sObject then if (c.Account != '') will always return false only
see this reference
http://salesforce.stackexchange.com/questions/110986/check-lookup-field-is-null-in-apex
Thanks and Regards,
Shiva RV