3

Background

I have a master-detail relationship between two objects, let's call them:

  • parent__c
  • child__c

Once the parent__c record is in a certain status__c we block any changes using a before update trigger.

But this same before update trigger on the parent__c object is blocking child__c records from being added.

Questions

  1. Is this an expected behaviour?
  2. What is the usual pattern to enable this situation and workaround this behaviour?
  • 1
    Does the parent record have any summary rollup fields on it or do you have any triggers / workflow on the child to update data on the parent? – Mark Pond Mar 21 '19 at 20:20
  • @MarkPond yes it does have rollup fields. – Robs Mar 21 '19 at 20:27
  • 1
    Related: salesforce.stackexchange.com/q/4531 – Mark Pond Mar 21 '19 at 20:29
2

Is this an expected behaviour?

Yes, this can happen because of Process Builder updates, triggers, and rollup summary fields. See Triggers and Order of Operation.

What is the usual pattern to enable this situation and workaround this behaviour?

The usual solution is to write triggers to set static variables to allow conditional bypasses. The specific solution often depends on the specific problem, however.

| improve this answer | |
  • Thanks sfdcfox. What the usual solution for allowing rollup summaries? – Robs Mar 21 '19 at 20:28
  • 1
    @Robs You'd probably want to check to see if that particular field was being updated, and if so, skip the error message. Each solution is likely going to be problem-dependent. – sfdcfox Mar 21 '19 at 20:31
  • How do I check to see if that particular field was being updated when it's the addition of detail record that's causing the trigger to fire? – Robs Mar 21 '19 at 20:33
  • 1
    @Robs In the parent record, you'd do something like for(parent__c record: trigger.new) { if(Trigger.oldmap.get(record.Id).RollupField__c != record.RollupField__c) { checkForErrors(record); } } This is again just pseudocode, but should get you started, I think. – sfdcfox Mar 21 '19 at 20:39
  • 1
    @Robs No worries, we all have our moments. – sfdcfox Mar 21 '19 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.