You need to sign in to do that
Don't have an account?
Carolina W 2
For loop inside For
Hi!
I want to avoid this For loop inside another For... Is there any way?
I want to avoid this For loop inside another For... Is there any way?
public class ManagerAccountTeamMember { public static Boolean isFirstTimeBEFORE = true; public static void myMethod (List<AccountTeamMember> TeamMembers) { for( AccountTeamMember accTeamMember: TeamMembers){ if(accTeamMember.TeamMemberRole == '001'){ isFirstTimeBEFORE = false; accTeamMember.Code__c = '001'; } if(isFirstTimeBEFORE) { isFirstTimeBEFORE = false; Map<String,AccountTeamMember> accId_X_TeamMember = new Map<String,AccountTeamMember>(); for(AccountTeamMember TeamMember : TeamMembers) { accId_X_TeamMember.put(TeamMember.AccountId,TeamMember); } List<Account> accounts = [SELECT Id,RecordTypeId,OwnerId FROM Account WHERE Id IN: accId_X_TeamMember.keySet()]; for(Account account : accounts) { if(acc.OwnerId != UserInfo.getUserId()) { accId_X_TeamMember.get(account.Id).addError('Msg'); } } } } } }
1 - I created a Set to add the AccountIds of AccountTeamMembers
2 - So I use the method contais to search the itens of the Set in the another for looping