0

I have trigger on parent object which is used to update field Status of child object, I want to update child object's status field to Tested only if previous values is "ready for testing". And once all child status field changes to "Tested" i want my parent object field changed to 'Awaiting deployment.'

I just need suggestion for this part. "I want to update child object's status field to Tested only if previous values is "ready for testing". And once all child status field changes to "Tested" i want my parent object field changed to 'Awaiting deployment.'"

How to approach this scenario, any help will be appreciated.

marked as duplicate by Derek F, David Reed, glls, Pranay Jaiswal, battery.cord Feb 26 at 15:50

This question was marked as an exact duplicate of an existing question.

  • You need to use trigger.oldmap (to check the previous value) – SFDC FAN Feb 26 at 4:44
0

I definitely recommend reading through the best practices found here.

Here's an overview of how you can approach this:

  1. Create your trigger (probably before insert, before update?)
  2. Query for the child records that meet your criteria and put them in a list.
  3. Make changes to child statuses.
  4. Make changes to parent fields.
  5. Update records.

Heres a watered down example of the child portion that might help:

   trigger updateChildStatuses on Parent__c (before insert, before update) {

        // Query child records
        Child__c[] childRecords = [SEELCT Parent__c, Status__c FROM Child__c WHERE Status__c = 'ready for testing' AND Parent__c in :Trigger.new ];

        // Update the child records
        for(Child__c c :childRecords){
            c.Status__c = 'Tested';
        }

        update childRecords;

        // Handle your normal parent field updates here
    }

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