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

Triggers for AccountTeamMembers?

AccountTeamMembers is a standard child object so I can't define a trigger for it but is there some other way I can catch changes to it in my Apex code?  If someone tries to add a new accountteammember and I want to do validations on their role how can I do that?
I need to do this as well.  I'm using Apex Managed Sharing as demonstrated in the Developer Guide.  I need to grant access to instances of a custom object based on membership in Account teams.  I'd like to write a trigger for the "after insert" and "after update" events on the AccountTeamMember object but see no way to do that.  Does anyone have any other suggestions for how this could be accomplished?

Similar challenge to both of you.  In my case I need to add the specific TeamMemberRoles from AccountTeamMember to the OpportunityTeamMember of every opportunity.  The convienence of using a trigger isn't available here, nor is there the ability to employ workflow against the AccountTeamMember object when a change occurs. 


This then causes you to consider the alternative, which has time sensitivity around it.  You can still accomplish in Apex, but not in realtime.  There will be some degree of delay - from 1 hour (using cronKit, but you can devise other means to initiate a workflow message more than once every hour - you can determine your appetite for delay.


You can create a class that has the code in it to perform this activity, and within that code check to see if the AccountTeamMember record was created or lastupdated within the last XX minutes (or hours/days, whatever your interval).  Your apex code then is coded to operate in mass-update type mode wherein you read for all AccountTeamMember records with created dates or updated dates within the last XX minutes, and from there you can apply your business logic, but from the mass-update type of mindset so that you don't overrun the governors.    Use of an Apex scheduler such as CronKit (free) from appExchange can be configured to fire off your Apex code on a regular schedule so that it can collect any recent changes and perform your processing against those changes.  Using the mass-update approach you shouldn't run into governor limit issues. 


I have a .NET solution in place to perform my AccountTeamMember needs in place today and it kicks off once per day at 2am, however we need it to be more timely than once daily, and if we are going to open up the .NET code to rewrite, we will adjust and rewrite it as an Apex job (which has the side benefit of me not having to provision for business continuity servers on my raised floor, nor provision any DR servers at our offsite).