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
Danny IncompanyDanny Incompany 

Trigger Update Field on Related Object

Hi,

I am working on a workflow tha does not seem to be working and I think, I should go for it with a trigger, but not sure.

So this is the scenario:

ObjectP__c
Has a picklist field called State__c

ObjectE__c 
-​Has a formula field called State__c that just adds the value of the State__c field in ObjectP
-Has a text field called State2__c (which populates value of State__c on same object with a workflow update rule every time it edits), so I can use it as a condition I need in a rollup summary field on ObjectO__c (since formula fields are not available for conditioning when creating rollup summary fields).
-Has a Master-Detail relationship to ObjectO__c

ObjectO__c
I have a rollup summary field called Amount__c which basically needs to count the related ObjectE__c child records, with the condition that it will count only the ones with the State2__c with value "Active" (that at the end is coming from State__c field in ObjectE__c)

The Problem
So my issue here is that if the field State__c value of ObjectP__c changes to a different value, for example "Inactive", the State__c of ObjectE__c will also change, however, the field State2__c will remain with the old value "Active" (since it will only change if I edit the ObjectE__c record to trigger the workflow), giving me an incorrect Count of "Active" child records on the rollup summary field on ObjectO__c.

It is not an option for the customer, that every time he changes the State on the ObjectP__c record, to make a second step and update the ObjectE__c record, so the value on State2__c will be same as in ObjectP__c to count correctly the records on ObjectO__c

So my question is, how can I achive this? With a Trigger? if so, can you provide an example? or there another option for achiving this? I may think of a trigger that every time ObjectP__c State__c changes to change the value automatically on State2__c field on ObjectE__c, with out having to edit the record and save it. I need the value of field State2__c field on ObjectE__c to always have the same value of State__c on ObjectP__c.

Thanks and any help is greatly appreciated. I am working on a school project and no way to find this.

Danny



 
Best Answer chosen by Danny Incompany
Shashi PatowaryShashi Patowary
Hi Danny,

Trigger is one of the options.But whenever there is a way to achieve thing using point and click it should be taken up.
Process builder allows to update child records from parent.Since you are using a having a forumula field in ObjectE__c, it has look up (or MD) to ObjectP__c. Now using process builder, you can update child record from parent.So using process builder can we update State_2__c in ObjectE__c  from State__c  of ObjectP__c field using proper criteria?

You will find help on how to update child record from parent here -

https://help.salesforce.com/HTViewSolution?id=000213419&language=en_US

Please let me know if this is helpful.

Regards,
Shashi

All Answers

Shashi PatowaryShashi Patowary
Hi Danny,

Trigger is one of the options.But whenever there is a way to achieve thing using point and click it should be taken up.
Process builder allows to update child records from parent.Since you are using a having a forumula field in ObjectE__c, it has look up (or MD) to ObjectP__c. Now using process builder, you can update child record from parent.So using process builder can we update State_2__c in ObjectE__c  from State__c  of ObjectP__c field using proper criteria?

You will find help on how to update child record from parent here -

https://help.salesforce.com/HTViewSolution?id=000213419&language=en_US

Please let me know if this is helpful.

Regards,
Shashi
This was selected as the best answer
samsafin42samsafin42
Is there some reason you cannot have the State2_c workflow based on the State_c of ObjectP_c as well? It seems that everything related to ObjectE_c is based on the initial change of ObjectP_c, so I would just include all field changes that you need in the single workflow that triggers when ObjectP_c is updated. 

Unless I am missing something...