You need to sign in to do that
Don't have an account?
Serah
Trigger to update a field on master object with a detail object field
I'm working with Opportunity object and OpportunityDetails object that have a master-detail relationship with one another. The master's api name is Opportunity and the detail's api name is Opportunity__Details__c.I have created a custom field in the Master object OppStatus__c.In that field I want to display the minimum status of field Status__c value of Detail object. The field Status__c is a picklist value field with values Closed,Pending,New . And i have multiple records in the detail object .
(If the Status field in any record contains New, then it should update OppStatus field with New.
I meant if in the records,
for eg, Record 1 the field Status has value Closed
Record 2 value is New, Record 3 value is Pending
Record 4 value is Closed
Then value should be updated in oppstatus is New.
If in Record 2 , the value is pending or closed insted of new., the min value is pending.
If all the values are closed, then the value closed should be updated.
Like new is the minimum if new is not present, pending is the min.
if pending is not present, closed is the min.)
How to populate the field in master object.
Thanks.
(If the Status field in any record contains New, then it should update OppStatus field with New.
I meant if in the records,
for eg, Record 1 the field Status has value Closed
Record 2 value is New, Record 3 value is Pending
Record 4 value is Closed
Then value should be updated in oppstatus is New.
If in Record 2 , the value is pending or closed insted of new., the min value is pending.
If all the values are closed, then the value closed should be updated.
Like new is the minimum if new is not present, pending is the min.
if pending is not present, closed is the min.)
How to populate the field in master object.
Thanks.
You could update it whenever the opportunity is updated, something like the following, but then you'll also have to update the opportunity anytime an opportunity detail record is updated. This could be a good back-up in case of some other failure or someone trying to force an incorrect status by updating the opportunity directly.
You could update the header status from a trigger on the opportunity detail, which is probably more efficient unless an update to opportunity detail is already forcing an update to the opportunity: