You need to sign in to do that
Don't have an account?
: Loop variable Compile error
I get Error: Compile Error: Loop variable must be of type Id at line 39 column 18 for the line for (Account a:AccountsIds){
How come? It works for the line for (User u:UserList) {
the debug logs tell me I created the ID in the list AccountsIds properly.
Please assist, thanks!
trigger TeamMemberAssignedtoTeam on Coverage_Person__c (after insert) { /*if the Team Member (coverage_person__c) is a User, link them to that User and add them to the Account Teams to all Accounts the Team is Assigned to. */ //lists List < EntitySubscription > esSet = new List < EntitySubscription > (); List < Double > empIds = new List < Double > (); List < AccountTeamMember > atms = new List < AccountTeamMember > (); List < string > CPUsers = new List < string > (); // List < AccountShare > ASSES = new List < AccountShare > (); List <id> covTeams = new List <id> (); //get list of emp ids from the coverage people inserted// for (Coverage_Person__c p: trigger.new) { empIds.add(p.Emp_Id__c); covTeams.add(p.Coverage_team__c); } system.debug('covTeams-----------'+covTeams); //get the users that match the inserted coverage people via emp id// List < User > userList = [select id, Emp_Id__c from User where isActive = True and userType='Standard' and EMP_ID__c IN: empIds]; system.debug('userlist--------------'+userList ); //Get the accounts covered by the team the person was added to List <Assigned_Team__c> TeamsAccounts = [select Account__c from Assigned_Team__c where Coverage_Team__c IN: covTeams]; system.debug('TeamsAccounts-----------'+TeamsAccounts); list<ID> AccountsIds = new list<ID>(); for(Assigned_Team__c es:TeamsAccounts){AccountsIds.add(es.Account__c);} system.debug('accountids--------------'+AccountsIds); //add the User to Account Teams for the Accounts for (Account a:AccountsIds){ for (User u:UserList) { AccountTeamMember atm = new AccountTeamMember(AccountID=a.id, UserId=u.id,TeamMemberRole='test'); atms.add(atm); } } insert atms; }
Thanks for the help guys -
I had collectred the Accounts, made them into a list of ids (AccountsIds), so here's what worked:
thanks!
All Answers
You need a list of accounts and not of Ids... List <Account> accList = [SELECT Id, Name FROM Account LIMIT 10]; something like that...
Then you should be able to loop through those. Otherwise you will need to do it old school... for (i=0; i<acclist.size(); i++)...
Try this.
Or this... the idea is to have a list of objects of the same type as your loop variable..
Thanks for the help guys -
I had collectred the Accounts, made them into a list of ids (AccountsIds), so here's what worked:
thanks!