+ Start a Discussion
Travis DvorakTravis Dvorak 

Relate AccountTeam object to User object using PB and Flow?

Hello.  Sorry in advance as I'm a newbie for deveopment.  Background to my scenario before I ask the question.  We use "Roles" as a way to differentiate the offices that are using our org.

We have a private sharing model for Accounts, Cases, Contacts and Leads.  Whenever a new office joins, or when a new employee for an existing office starts, we need to udpate the Account Team for each user as every user within a specified role should have edit access to Accounts, Contacts, Leads and Cases.  

I have created a flow that, when a user is created, it will automatically add that user to other users in that roles Account Team, and add the existing users to the newly created users Account Team.

Works perfect, except a HUGE flaw - it only works for accounts that are created after the created date of the user. 

So it doesn't check the box of "Update Account teams with these members" like you can do when you manually add users:

User-added image

I tried to experiement with making my flow gather existing accounts and add that user to that Account Team, but I'm getting an error of:

Error Occurred: This error occurred when the flow tried to create records: MIXED_DML_OPERATION: DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): AccountShare, original object: User. You can look up ExceptionCode values in the SOAP API Developer Guide.---

I understand why this is happening - the way this is triggered is by Process Builder on the User object.  The user object can't reference Accounts, which means I'm going to have to build a trigger (I think?)

I'm by no means asking for anyone in the community to build this for me, but at least let me know if what I want to accomplish is possible?  

Or, if a trigger isn't necessary, is it possible to somehow tell my flow to check that stupid box that will solve all my problems?

Hemant_SoniHemant_Soni
Hi Travis Dvorak,
As per my understanding you can write trigger and in trigger you should use FUTURE method and that will definatly work for you.
Please let me know if you have any issue.
Thanks
Hemant