+ Start a Discussion

Trigger Help For A Rollup & Field Update

I know almost nothing about Apex and looking for help. I know for this use case I will need a Trigger, however. 

Here's the use case: 

My company has 8 oven slots(manufacturing), and 2 cycle AM and PM for a total of 16 total usable slots(8 each cycle). I need to measure the success rate of each slot during the AM and PM based on the # of orders gone into the specific slot. 

Here is how i've set it up thus far: 
I have a child related list (Audits__c) to a master (Order_Summary__c). Each "audit" record has a field "AM Oven Slot__c" and "PM Oven Slot__c" both are ranged 1-8 in a picklist, and finally there is a "Outcome_Result__c" picklist field with "Good" and "Fail" 

I have already used 16/25 rollup summaries to count the # of line items that go into each tray in the AM and PM, respectively. 

Now, I need a Trigger to COUNT the number of "Good" Outcome_Result__c for each respective tray # and update the respective number field. 
For example, it will SUM the # of "good" outcome results for Tray 1, and then insert that number into "Total Successful outcomes AM Tray 1" 

I think I need to do a BEFORE trigger since I don't need to utilize the record ID, and a list?? 


rajat Maheshwari 6rajat Maheshwari 6

Hi Bill,

Hope you are doing great !!!

I would like to setup the meeting with you regarding the same, for more understanding. 


Rajat Maheshwari


Hi Rajat,

Here's some more detail on my use case: 

I have a custom object "Order Summary" that has a child object "Audits" (master-detail)
I have the following fields on each "Audit" Record

AM Cycle Oven Slot Number (Picklist values 1 through 8) 
PM Cycle Oven Slot Number (Picklist values 1 through 8)
Outcome Result (Picklist values Good, Bad)

Each "audit" record represents a single product being processed/audited. And I have a rollup summary field (count) on the master "Order Summary" object that counts the # of entries for AM oven slot and PM oven slot, this tells us how many individual products went into each slot for this order in the AM or PM cycle. 

What I need to do is (to circumvent the max # of 25 rollup summaries on an object) is to create a trigger that will  do the following pseudo code: 

1) Count # of Outcome Result = Good records for AM Cycle Oven Slot #1 (SOQL query?)
2) Take the number of counted records that meet #1 critera and input them into a field "AM Cycle Oven Slot Number 1 Total Successes" 

Then continue the same process for AM Cycle Oven Slot #2, 3, 4, 5, 6, 7, 8, then PM Cycle 1-8 

Essentially what i'm trying to do is run a formula on the declaratively rolled up # of audit records for each oven slot and divide with # of success for that oven slot for am and pm cycle to provide a success %

I think i'll need a bunch of SOQL queries and field updates, right? How would I write this?