3

I want to be able to update a lookup field "FirstUser"(lookup to user) with the value form another lookup field (CreatedbyID). What is the simplest way to do this? Do I need to create a trigger? I only want this to fire when the record is created. Therefore if USerA creates the record, the field "FirstUser" should be updated with the value of CreatedByID.

4 Answers 4

3

You have a few options

  • An Apex trigger. See Here
  • a Custom Button with a URL hack. See Here
  • publisher actions with predefined fields. See Here

If you use chatter I would recommend the publisher action over a URL hack as PA's are supported and url hacks are not.

My one question would be the use case. If you are setting the 'First User' field to the CreatedById, I don't se the purpose as the CreatedById field will never change, so in reality, the CreatedByID will always match the First User Field.

Maybe you are talking about the owner field and not the created by field?

8
  • I'm interested in the concept of using PA. The use case is as follows: When a case changes to a specific status then an email would be fired out to the user stored in the "firstUser" field. (I should have renamed this field to "Internal Contact"). The case user can update the "FirstUser" field to some other user via the lookup, so in the case the someone creates a case for another user, then they can update that field and when the case is set to the specific stage and email will fire out to that user instead of the one that created the case, but in most cases the default will be fine.
    – Bartley
    Commented Aug 1, 2014 at 14:18
  • Ok, so look at the link that I provided for PAs. You can set the First User field to the CreatedBy field by default on creation. The field can still be left open and can be changed, but it will be set to the CreatedBy User by default on creation. Commented Aug 1, 2014 at 14:22
  • Lengendary, will try that now.
    – Bartley
    Commented Aug 1, 2014 at 14:24
  • Another good post on using PA's to pre-populate values. [salesforcewizard.wordpress.com/2014/01/08/… Commented Aug 1, 2014 at 14:27
  • Sorry, that link doesn't go anywhere useful for me.
    – Bartley
    Commented Aug 1, 2014 at 14:40
4

Yes, you will need a trigger as workflows rule cannot update lookup fields. It should be a very simple trigger

Notice that createdbyid will most likely be null on a before insert context, so it has to an after insert or before update.

The custom button/link solution posted above would not work with integrations or data loads.

2

You would need to do a trigger or a custom button with a url hack. A good resource for the url hack options can be found here.

1

You cannot update lookup fields by field updates, so yes, you would need a trigger to get this to work. However, what is the purpose of your custom lookup? Depending on the goal, you could look into:

  • Storing the first owner's name or ID in a custom text field, which can be done by workflow
  • Use Feed Tracking to track changes on the owner field

The second option will however not let you filter on the original owner only.

1
  • Thanks Robin, I want to be able to use an email template that the workflow would send an email to a recipient that is stored in the "FirstUser" field. To begin with this field would have stored the CreatedByID user but could also be overwritten by a case worker to some other user (by looking up another user), in fact this field would be called the "internal contact".
    – Bartley
    Commented Aug 1, 2014 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .