0

I have a trigger on the event sObject that populates a few fields when the event is created off the account, contact or opportunity sObjects. This all works fine.

If the account is updated, I need to update the event record with the changed field values. I can do this with a trigger, but I was wondering if there is a way to fire an update on the event when the related account is updated since it already has the logic in place to set those field values with the event trigger. Ideally, I'd like avoid adding another trigger to update the event trigger. Is this possible?

2

The Event object has a lookup to Account, AccountId, that is populated by the system according to some specific criteria:

Represents the ID of the related Account. The AccountId is determined as follows.

If the value of WhatId is any of the following objects, then Salesforce uses that object’s AccountId.

  • Account
  • Opportunity
  • Contract
  • Custom object that is a child of Account

If the value of the WhatId field is any other object, and the value of the WhoId field is a Contact object, then Salesforce uses that contact’s AccountId. (If your organization uses Shared Activities, Salesforce uses the AccountId of the primary contact.)

Otherwise, Salesforce sets the value of the AccountId field to null.

If the rubric that Salesforce uses to populate that Account lookup works for your purposes, you can create formula fields that directly reference fields on the Account:

Account.Name

would return the account name, even if the Account itself isn't the What link on the Event but rather an Opportunity.

Then you don't need any triggers at all! But if that doesn't work for you, you do need the two triggers to which you refer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.