twittergoogle_pluslinkedin

Have you ever created a formula field on a record and attempted to reference information from that record’s owner, such as a custom field that you have on the User object? All you can pull into your formula is the Owner ID! It’s quite the rude awakening, isn’t it?

Formulas cannot transverse the standard owner lookup record, but they can with custom ones – just another of the charming quirks of Salesforce. For those of us who aren’t very fluent in Apex code, this can be pretty unfortunate!

However… there is an easier way to make those custom fields available, and all you need is one trigger. What’s more, it has already been written for you. This is one of the easiest customizations, I have ever done, and I’m no developer. Here’s how to do it:

1) In your sandbox, create a custom Lookup Relationship field on the Account object (I named my custom field “Owner Copy”). Relate it to the User object.

2) Also in your sandbox, create a new Trigger on the Account object. Use this code, substituting the name of your custom field for Owner Copy:

3) Use outbound and inbound change sets to deploy your custom field and your trigger to your production instance. (New to change sets? Watch this quick demo – they are super easy!)

You’ve now made a field that is just a copy of the account owner, and created a trigger to map the owner’s name to that field. After mapping, a separate formula field can be used on your custom field to move up the user record and pull whatever information is needed (generally role name information or custom user object fields, but it can be used for anything including alerting delegated approvals or managers, etc).

So now when I go to create my formula field, I can access all of the fields that exist in the Account owner’s User record:

Note: You can also create this trigger for other objects. Just replace ‘Account’ with whatever object you prefer (Lead, Contact, Opportunity).

Lastly, I’m very lucky to have a friend who is generous with his advice and incredible knowledge of Salesforce – so I need to say thanks Gabe!! (a.k.a. John Gabriel Athitakis) This trigger saved me a lot of grief. I hope it can do the same for my readers.

Liked this post? Follow this blog to get more. 

4 Responses

  1. avatar jager says:

    I sure wish your code was copy and pasteable instead of images – but still, great tips and thank you!

  2. avatar Adam says:

    I’m a little confused about changing this for Leads. I changed the value to 00Q and it didn’t fire, but isn’t that because user records in Salesforce ALWAYS start with 005?

    As I understand it, the trigger is checking to see if the owner starts with 005 (isn’t a queue), and fires if so.

    Actually, having it with 005 worked, but I get an attempt to de-reference a null object error whenever a lead comes in through web-to-lead with this.

    • avatar Celeste says:

      You’re right, the ‘005’ should not be changed. I was misinformed on that bit – I have updated the post to avoid confusion. Good catch!

  3. avatar Chris says:

    Disregard last message. I figured it out and got it working