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
mshroyermshroyer 

Trigger to update field on a custom object based on info from a task submitted on the Account

I'm kind of new at this apex stuff. Don't know if this is even possible

I have a custom object (Cadence Checkpoint) that is a child object to the account. What we need is when a task is completed on the account, a field gets changed on a Cadence Checkpoint related to the same account.

 

First, When a task is saved as "completed" look at the Account ID it's related to.

 

Second, Check to see if there are any Cadence Checkpoints that are also related to that same Account ID.

 

Third, If there are related Cadence Checkpoints, look to see if the task record type matches up with the Activity Type field on the Cadence Checkpoint ("log a call" record type on a task would match up to "contact - phone call" picklist value on the cadence)

 

Fourth, if the record types match, change the date field on the Cadence to "Today"

 

Any and all help would be greatly appreciated. Thank you!

-Meaghan

SammyComesHereSammyComesHere

Best  way of achieving it would be  trigger.

 

1) from Trigger.New get the Account Id,

2) use a select query for getting associated activities based on Trigger.New.AccountId and Trigger.New.Type

3) If mathes set the date value as Today.

 

A before insert would be preferable.

mshroyermshroyer

Yeah, I know what needs to happen, I just don't know the correct syntax to use. Like do I need to use a list, set, or map to get the account ID from the task. Then how do I make sure that I'm only pulling Cadence Checkpoints that are related to the same account ID as the task. Also, what's the best way to pull the record type for the tasks (probably a query on Record Type but with a list, set, or map?)and whats the best way to match them up to the Activity type field on the Cadence Checkpoint?