+ Start a Discussion
HoltzyHoltzy 

Trigger to update field across two objects

Hello,

 

I am a new developer and working on my first coding project.  Here is my scenario:

 

I have a custom field on the Account object that I want to have populated with the contents of a field that resides on a separate custom object.  This update should happen anytime the custom object field is edited.

 

Here's another way of explaining it:

 

Account (Object 1)                                                                              Producer_Role_Code__c (Object 2)

Producer_Role_Codes__c (Field 1)                                              Role_Code__c (Field 2)

 

Anytime a new value is entered into Field 2, it should populate into Field 1.

 

Object 2 can have more than one Field 2 entry, so Field 1 will need to be able to display each Field 2 entry separated by a comma.

 

Additional info:

Object 2 is a related list on Object 1.

I have tried to make Field 1 a Formula(Text) field that pulls in the data from Field 2 but that did not work.

 

Any help/guidance you can provide would be greatly appreciated.

Cloud CredenceCloud Credence

Hi,

 

I think, this can be achieved using master detail relationship and a formula field. You don't need apex code.

 

You need to have a relationship field created in Object B for Object A(as Master Detail Relationship).

 

If Object A, write a new forumula field(use advanced formula tab), you can concatenate the value of the different fields in Object B.

 

Best Wishes,

MoggyMoggy

You not necessarily need a master detail ( careful with that) lookup relationship should do it as well.

 

Can you post the formula you tried and explain what doesnt work

 

Field 1 and Field 2 both part of object 2 right? if so you don't need any relationship created

 

did you tried a workflow criteria formula every time when a record is edited

priorvalue(field2 ) <>field 2

 

if true then>> field update on field1 (formula) field1.text = field1.text + ',' + field2.text  (or whatever value is in there)

 

 

HoltzyHoltzy

Thanks for the response.  Let me add some additional detail here...Each Role_Code_c value is a separate entry, for instance one Account could have up to 10 individual Role_Code_c entries associated to it.  How do I write a formula to call on each individual entry for the Role_Code_c field and have all of them populated (as a string) into the Producer_Role_Codes__c field?