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
King KooKing Koo 

Contact.Name requires NULL in triggers

Hi guys

 

Don't know if I missed something or if there are some reasons for that.

 

I was trying to create a before update trigger for contact but I was encountering some problems, and it turned out it's because the Contact.Name requires NULL.

 

I have a contact whose last name is "LastName" and whose first name is "FirstName".  I assume underneath, the Name attribute of this contact is set to "FirstName LastName".

 

The trigger code is like this:

trigger testcontact on Contact (before update) 
{
  for (Contact c : Trigger.old)
    system.debug('old ' + c.name + ' ' + c.firstname + ' ' + c.lastname) ;

  for (Contact c : Trigger.new)
    system.debug('new ' + c.name + ' ' + c.firstname + ' ' + c.lastname) ;
}

 

When I opened up this Contact, and without editing anything, just hit Save, this is what's in my debug log:

[25]DEBUG|old null FirstName LastName

[28]DEBUG|new null FirstName LastName 

 

Anyone has any idea why Contact.Name returns null and not the actual name of the contact?  I understand this is a formula field, but when I do a soql like this:

SELECT Name FROM Contact WHERE LastName = 'LastName'

it does return me 'FirstName LastName'.

 

So I don't know why I can't access this inside a trigger.

 

Thanks

 

 

kriskkrisk

Contact Name is designed a formula field and is not stored in the database.

 

It is only calculated as a concatenated string using firstname and lastname and displayed on the UI.

 

So that is why you are not able to access in the Trigger context.

 

Others please correct me if I am wrong.

King KooKing Koo

Hi krisk

 

Thanks for your reply.  As I mentioned in my original message, I understand it's a formula field, but I don't know if that is the reason why I get NULL in the trigger.

 

If that is the case, that would mean any formula fields, standard or custom, will also become NULL in the trigger...?  (I should probably investigate it)  If that's the case, that almost sounds like a bug to me.

 

I'll keep digging to see what else I can find.

 

Thanks

King