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

Partner Portal:Trigger addition of sales team by adding a partner to the oppty

I'm looking for help on how to tackle this need: we want to trigger the addition of several AEs to the sales team (all partner users) of an opportunity when their partner account is added as a partner to the opportunity. I'm completely stuck. Any ideas?

Interesting question.  The three word answer is: Scheduled Batch Apex.


Remember that the SalesTeam object can handle duplicates; it actually deduplicates itself.  So you can run a batch regularly that goes through the OpportunityPartner table, checks if the account is a partner account, and then adds all the partner users from that account to the SalesTeam object.  It is an automatic upsert.


SalesTeam member fields are found at


Note: Unless you put additional filters, this will go through all OpportunityPartner records and will add all partner users from those accounts.  You may wish to limit to Opps created after a certain date, Opportunities by record type, etc. 


Don't forget to bulkify the actions: Collect all the AccountIDs and query all partner users with that AccountID.  Then for each opportunity,  add all matching partner users.  Don't forget to include exception handling in casea given AccountID has no corresponding partner users.



Not the most elegant solution, but until we can trigger from OpportunityPartner or AccountPartner (not likely anytime soon) it's a workaround.


Hope this helps or at least gives you a starting-point.



My scenario is a little different.  I'd like to add the current Opty Owner to the Sales Team and change the owner to a specific individual when a particular set of Opty criteria are met.


I can do the owner change with Workflow and I know that Default Sales Teams might do some of the work to make sure that current owner gets added to the Sales Team, but that would not be the ultimate solution because it might not always be the original creator that needs to be added to the Sales Team and not all Opportunities meet the criteria where I want this to occur.


Instead, I was thinking that an Apex trigger would work better because it can capture the current owner and update the Sales Team only when the Opty meets the criteria.


I'm an Apex rookie, so any advice on how to go about building the code for this trigger?  (Examples are most appreciated).  Also, if do-able, does anyone have any advice on which fires first - workflow or trigger?