0

I would like to nullify a text field on a object record after its saved. There is a after update trigger that copies value of this record to its child object records. I cannot use before trigger, otherwise this field will always be null.
Can I use a after update trigger to update same record? If yes, how to avoid recursion?

Thanks

3
  • you are most likely going to need a custom field to record state in the parent object (that indicates that the operation of propagating the text field has completed). This will aid in recursion control
    – cropredy
    Commented Aug 27, 2019 at 17:58
  • How about, i leave the trigger alone. The trigger will populate the value from this text field in the child records. Then, a workflow always makes this field null. Will this work? WF comes after the After Trigger in order of exec right?
    – KLab
    Commented Aug 27, 2019 at 18:13
  • the WFR will cause the triggers to refire. See Triggers and Order of Execution
    – cropredy
    Commented Aug 27, 2019 at 18:33

1 Answer 1

1

There are at least three potential solutions. You could choose to use Process Builder, since it would run after your after-update trigger. For that matter, you could copy the text values to the children using Process Builder as well, which would avoid the need for any code. Aside from that, there is no hard rule preventing you from updating children in a before update trigger, if you know there is no logic that will alter that field's value later. This "rule of thumb" is meant to be more of a guideline, and there are circumstances when it is certainly acceptable to break this rule. If all else fails, then a @future or Queueable call would also be appropriate for blanking out the value later.

1
  • Thx, but we cannot use process builder as the trigger on this object is doing otherthings as well. We dont wanna have trigger and a PB on the same object. I did not quite understand your 2nd point, I cannot use a before update to update my child records, as the children records are inserted/updated depending on criteria on the parent record.
    – KLab
    Commented Aug 27, 2019 at 16:39

You must log in to answer this question.

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