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
Suman MSuman M 

Compile Error: Expression must be a list type: SET<Id>

Hi,

Below is my class

public class opptytemlisttrigger
{
    public static Map<id,set<id>> statuids = new Map<id,set<id>>();
    @future
    public static void beforetriggermethod()
    {
     system.debug('UseridsrecievedfrombeforeTrigger'+statuids);
    }
    public static void aftertriggermethod(set<id> newaccid)
    {
        Map<Id, List<OpportunityTeamMember>> newopptytemmemmap = new Map<Id, List<OpportunityTeamMember>>();
        system.debug('AccountIDsreceivedfromtrigger'+newaccid);
        system.debug('UseridsrecievedfrombeforeTrigger'+statuids);
        tr_Opportunity_Sales_Team_Delete__c delSalesTeamObj = new tr_Opportunity_Sales_Team_Delete__c();
        List<tr_Opportunity_Sales_Team_Delete__c> deleteTeamInsert = new List<tr_Opportunity_Sales_Team_Delete__c>();
        List<Opportunity> newopptyinfo = [SELECT Id, OwnerId from Opportunity where AccountId IN : newaccid];
            system.debug('OpportunityDetailsafterchange'+newopptyinfo);
            List<OpportunityTeamMember> newopptytemlist = [SELECT UserId, OpportunityId FROM OpportunityTeamMember where OpportunityId IN : newopptyinfo];
            system.debug('OpptyTeamqueryafterupdate'+newopptytemlist);
            for(OpportunityTeamMember newoppttem : newopptytemlist)
            {
                 if(!newopptytemmemmap.containsKey(newoppttem.OpportunityId))
                 {
                     newopptytemmemmap.put(newoppttem.OpportunityId, new List<OpportunityTeamMember>());
                 }
                 newopptytemmemmap.get(newoppttem.OpportunityId).add(newoppttem);
                 system.debug('OpptyTeamDetails after change**'+newopptytemmemmap);
            }
        if(newopptytemlist.size()>0)
        {
            for(Integer i=0;i<newopptytemlist.size();i++)
            {
                if(string.valueOf(statuids).contains(newopptytemlist[i].UserId))
                {
                    system.debug('EnteredintoIfLoop');
                }
            }
        }
        else if(newopptytemlist.size()==0)
        {
          for(Id optyid: statuids.keyset())
          {
              Set<id> temp = new Set<id>();
              temp=statuids.get(optyid);
              for(Integer i=0;i<temp.size();i++)
              {
                  delSalesTeamObj.tr_team_member__c = string.valueOf(temp[i]);    // Here is where I'm getting the error -> Compile Error: Expression must be a list type: SET<Id>

                  delSalesTeamObj.trOpportunity__c = optyid;
                  delSalesTeamObj.tr_action_type__c = 'Deleted';        
                  deleteTeamInsert.add(delSalesTeamObj);
              }
              system.debug('***deleteTeamInsert***'+deleteTeamInsert);
          }
        }
        if(!deleteTeamInsert.isEmpty())
        {
              Database.SaveResult[] sr1 = Database.insert(deleteTeamInsert,false);
        }       
    }
}

Could someone help on how to fix the error. Thank You.
bob_buzzardbob_buzzard
While you can treat a List as an Array, you can't treat a set in the same way, so the square bracket notation is the problem here.

You can't extract elements from a Set by position, as they aren't stored in order.  Thus you just have to iterate the entire set in the order that the platform wants to return them:

             for(Id tempId : temp)
              {
                  delSalesTeamObj.tr_team_member__c = string.valueOf(tempId);  

                  delSalesTeamObj.trOpportunity__c = optyid;
                  delSalesTeamObj.tr_action_type__c = 'Deleted';       
                  deleteTeamInsert.add(delSalesTeamObj);
              }