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
Julian Juez AlfaroJulian Juez Alfaro 

Apex trigger to update Account field with custom child object information

Dear all,

 

I have the following:

Account

      |

      |> Custom Child Object (called "Survey_Summary")

 

Inside the "Survey_Summary" child object, there might be 0, 1 or multiple records.

Inside each record, there is a custom nummeric field (let's call it "Number") that can take the values 0, 1, 2, 3 or 4.

 

I would like to update an Account custom field (let's call it "HasAnsweredNegativeSurvey") like this:

If the "Number" field of all of the "Survey_Summary" records = 0, then update the Account custom field to "No". This sentence can be rephrased to:

If the sum of the "Number" field of all of the "Survey_Summary" records = 0, then update the Account custom field to "No".

And then, If the "Number" field of any of the "Survey_Summary" records = 1, then update the Account custom field to "Yes". This sentence can be rephrased to: If the sum of the "Number" field of all of the "Survey_Summary" records = 1, then update the Account custom field to "Yes".

 

Our support engineers use the Console, and the purpose is that whenever they click on an account or view a case, they see whether that company has already answered our customer satisfaction survey in the past with negative answer(s), so that the Account gets extra attention.

 

Any idea where to start?

 

Thank you,

Julian.