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
emuelasemuelas 

Trigger Help:Update parent status based on child records changes

Hi ,

 

I need  to write a trigger that updates the parent object field 'Status__c' based on its child statuses.

I have a custom parent object Order__c and child object Order_line__c

 

Both have a status field "status__c"

 

Now when the any of the child object status__c ='Open' ,the parent status__c is 'Open'
else the parent object status__c='Closed'.

 

I tried writing a trigger from the docs example,but it was confusing .....

 


Can somebody please help me with this?

Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
EnthEnth

You don't need Apex for this.

 

Add a Roll Up Summary to Order, to use Count on OrderItem where status = 'Open'.

 

Then add a formula field to Order to display the status of Open if the RUS Count > 0 or Closed if it's 0.

 

Simples ;-) 

All Answers

EnthEnth

You don't need Apex for this.

 

Add a Roll Up Summary to Order, to use Count on OrderItem where status = 'Open'.

 

Then add a formula field to Order to display the status of Open if the RUS Count > 0 or Closed if it's 0.

 

Simples ;-) 

This was selected as the best answer
emuelasemuelas

Hi Enth,

 

This was wonderful!!!!!!!!!!!!!!!!!

Thanks so much!!