You need to sign in to do that
Don't have an account?
Nirav_Shah
Add TeamMemberRole from List to Set
Hi Folks,
Following is my code
As you can see I have to use multiple iterations(For Loops) just to add Team Member Role to set of String, can you guys please suggest me some better way of doing this
Thanks
Following is my code
List <AccountTeamMember> teamMemberList = new List <AccountTeamMember>(); Set <String> teamMemberRole = new Set <String>(); if(accountDetail.Ultimate_Parent__c && accountDetail.Parent__c){ teamMemberList = createTeamMemberList(accountDetail.Id, teamMemberRole); } else if(accountDetail.Parent__c){ teamMemberList = createTeamMemberList(accountDetail.Id, teamMemberRole); for (AccountTeamMember tm : teamMemberList){ teamMemberRole.add(tm.TeamMemberRole); } if (!teamMemberRole.isEmpty() && teamMemberRole.size() != 4){ teamMemberList.addAll(createTeamMemberList(accountDetail.ParentId, teamMemberRole)); } } else{ teamMemberList = createTeamMemberList(accountDetail.Id, teamMemberRole); for (AccountTeamMember tm : teamMemberList){ teamMemberRole.add(tm.TeamMemberRole); } if (!teamMemberRole.isEmpty() && teamMemberRole.size() != 4){ for (AccountTeamMember tm : createTeamMemberList(accountDetail.ParentId, teamMemberRole)){ teamMemberRole.add(tm.TeamMemberRole); teamMemberList.add(tm); } } } // Create Account Team Member List public static List<AccountTeamMember> createTeamMemberList (Id accId, Set <String> teamMemberRole){ Final List<String> roleList = Label.CCP_TeamMemberRole.split(','); return [SELECT User.Name, User.Email, user.Phone, TeamMemberRole, user.FullPhotoUrl, Account.Name, FROM AccountTeamMember WHERE AccountId =: accId AND TeamMemberRole NOT IN: (teamMemberRole) AND TeamMemberRole IN: (roleList) AND User.isActive = true]; } }
As you can see I have to use multiple iterations(For Loops) just to add Team Member Role to set of String, can you guys please suggest me some better way of doing this
Thanks
All Answers
Where is the accoutnDtail is coming from?
Is this code calling form trigger?
What exactly is getting set in the teamMemberRole which are passing to createTeamMemberList as it is just getting intialized?
Please tell what excatly you are trying to do here.
Below is the complete code...
The requirement is I need to expose the team members details to external team and for that I have created this rest resource. We have three level hierarchy in Account, Ultimate Parent Account, Parent Account and Child Account. Each Account has team members associated with it and I wanted to expose some specific team member.
I have three levels of Account Hierarchy and all three account has Team Member associated with it. I want to fetch the user/team member with role AE, AM and SE Account
Account : A1 -> Ultimate Parent Account,
Team Member : T1 Role : AE, T2 Role : AM, T3 Role : SE
A2 -> Parent Account
Team Member : T1 Role : AE, T2 Role :AM
A3 -> Child Account
Team Member : T1 Role : AE
(A3 -> A2 -> A1) A3 is Child, A2 is Parent of A3 and A1 is Parent of A2
Now let's consider following scenario, let's say Account -> Child Account If the Child Account has the above roles, then bring up all individuals associated with these 3 roles. If the CA does not have individuals associated with any of these roles, go to its Parent Account and get the names of the individuals for that role. If the PA also does not have individuals associated with that missing role, go to its Ultimate Parent Account for the name against the role.
Thanks
Sorry it took little time. This is how I think will work in your case. I have tried but I hope it work, at least it will give some design thought
One thing you are checking Team Role with 4 and with 3.
I added the following new Method. It will in first place get you based on which account you are on. It will work upwards.
Now I change your entire code To this
Let me know your thought.
Thanks for your response.
My concern here is, there are multiple for loops in which SOQL query are being executed which can be resulted in Governer Limit.
I have talked with my lead and what he suggested is to take all the TeamMembers in one Map (Including Ultimate Parent Account, Parent Account, and Child Account) and then iterate on that map to get a result. But I don't have much idea on how to achieve that. If you can please give your inputs for the same.
Thanks
I think your requirement is to stop looking at the parent if you find your desire roles on the child.
My requirement is to find the desired role from all the level.
For E.g.
I have three levels of Account Hierarchy and all three account has Team Member associated with it. I want to fetch the team member with role AE, AM and SE
Account : A1 -> Parent Account,
Team Member : T1 Role : AE, T2 Role : AM, T3 Role : SE
A2 -> Sub Parent Account
Team Member : T4 Role : AE, T5 Role :AM
A3 -> Child Account
Team Member : T6 Role : AE
(A3 -> A2 -> A1) A3 is Child, A2 is Parent of A3 and A1 is Parent of A2
Now let's consider following scenario, let's say
Account -> Child Account
- If the Child Account has the above roles, then bring up all individuals associated with these 3 roles. If the CA does not have individuals associated with any of these roles, go to its Sub Parent Account and get the names of the individuals for that missing role. If the SPA also does not have individuals associated with that missing role, go to its Parent Account for the name against the role.
- it should give result as T6 Role AE, T5 Role AM, and T3 Role SE
Account -> Sub Parent Account- If the Sub Parent Account has the above roles, then bring up all individuals associated with these 3 roles. If the SPA does not have individuals associated with any of these roles, go to its Sub Parent Account and get the names of the individuals for that missing role.
- it should give result as T4 Role AE, T5 Role AM, and T3 Role SE
Account -> Parent AccountThis works after some Modification