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
lopezclopezc 

Can I update a lookup Contact field using Workflow rules?

Hi,

I need to update the Owner Id of a Contact each time it is inserted/updated. The Owner Id for Contacts is assigne to each Contact based in some criterias.  That is why I was thinking to use workflow rules, however I couldn't find any lookup fields in the list when I chose to update a field in the workflow action options. I really need to update Owner Id for each contact based in custom fields values... Is there any other way to do it if this one is not possible???

Any help?

many thanks!
arnt72arnt72
you can do that using a field update workflow rule. However, you can specify exactly one new owner. If the number of criteria and respective owners is limited, you can create separate rules and field updates for eacg possible scenario. If that is not viable, you might want to try a lookup table in a custom object and write a trigger that pulls the ownerID from there works for us but we have just a single criterion determining the Owner).


Message Edited by arnt72 on 10-13-2008 05:16 PM
MSVRadMSVRad
I am trying to write a trigger that updates a standard lookup field.  How did you go about writing yours - what was your logic behind it?
arnt72arnt72
in a hurry, so brief reply:
you want to set the lookup field to the ID only of the record that is referenced, not the record as such..
Hope that helps,
Arnt
cafe2cafe2

Hi,

 

I'm having the same problem and for some reason can't figure out how to set the lookup field to the ID. I only get the option of looking up the object, not the ID. Am I missing something? Thanks in advance for your help!

 

ahab1372ahab1372

Although the lookup field points to the object and (in the web interface) always shows you the record's name, the actual value in there is the ID only.

 

here is some pseudo code, assuming that you have a contact myContact und you want to link it to the Account "Acme":

Account myAccount = [select ID, name from Account where name = 'Acme' limit 1];

myContact.AccountId = myAccount.ID;

 

 

 

Message Edited by ahab1372 on 10-13-2009 11:33 AM
cafe2cafe2
Sorry to bug you about this again! I'm a code novice -- much more comfortable in the point-and-click development environment. Should I be doing this in workflow? I am unable to create the rule because I am not given the option of updating that field. Should I be trying to create an apex trigger with the code?
ahab1372ahab1372

point and click configuration has always been and still is one of the key benefits of sfdc. But in some cases (like this one), you reach limits of what you can do. I just tried and the Account is actually not available for a firld update.

 

You can of course try writing a trigger, but if you have no previous code experience, get ready to spend some time to read the documentation or find a consultant doing it for you. The latter might be more time efficient if you are not planning to learn to code anyways. If you are interested, it can be a lot of fun.

 

Here is a good point to start, the Apex Code developers' Guide:

http://www.salesforce.com/us/developer/docs/apexcode/index.htm