+ Start a Discussion
brozinickrbrozinickr 

Help Troubleshooting a Trigger for Lead Assignment

Hello!

 

I have some code listed below that I was hoping someone would be able to help me troubleshoot.  The code is supposed to assign the owner of a Lead based on what Account Team of the User.  So when the lead is created, if select "Storefront" for Lead_Direction__c picklist, then it should assign to the Account Team Member on the Account labeled as 'Storefront Associate'.  If the I select Big Deal in the picklist, then it should assign to the Account Team Member for the associated Account labeled as the 'Big Deal Associate'.  It works when I select Storefront in the Lead Direction and assigned the appropriate rep, but it doesn't assign correctly to the Big Deal Rep.

 

trigger OpportunityTrigger on Lead (before insert){

    List<String> accountIds = new List<String>();
    
    List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
    parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds];
    
    Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>();
    
    for(AccountTeamMember a : parentAccounts){
    
        accountMap.put(a.AccountId,a);
    }
    
    for(Lead lead : Trigger.new){
    
        AccountTeamMember parentAccount = accountMap.get(lead.Account__c);
        String memberRole = accountMap.get(lead.Account__c).TeamMemberRole;
        
        if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){
        
            lead.OwnerId = parentAccount.UserId;
            
        }
        
        else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){
        
            lead.OwnerId = parentAccount.UserId;
          
        }
        
        else{
        
        lead.OwnerId = lead.OwnerId;
        
        }
        
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
s_k_as_k_a

Can you take debug log for below code.

trigger OpportunityTrigger on Lead (before insert){

   Set<Id> accountIds = new Set<Id>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
   
    Map<Id,List<AccountTeamMember>> acctToAccTeanMemsMap = new Map<Id,List<AccountTeamMember>>();
    
    for(AccountTeamMember atm : [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds])
	{
       if(acctToAccTeanMemsMap.containsKey(atm.AccountId) && acctToAccTeanMemsMap.get(atm.AccountId)!= null)
		{
            List<AccountTeamMember> accountteamMems = new List<AccountTeamMember>();
			accountteamMems = acctToAccTeanMemsMap.get(atm.AccountId);
			accountteamMems.add(atm);
			acctToAccTeanMemsMap.put(atm.AccountId,accountteamMems);
		}else
			acctToAccTeanMemsMap.put(atm.AccountId, new List<AccountTeamMember>{atm}); 
    }    
    
    for(Lead lead : Trigger.new)
    {
       
		
		System.debug('******AccountId on Lead is**********'+lead.Account__c);
        if(acctToAccTeanMemsMap.containsKey(lead.Account__c) && acctToAccTeanMemsMap.get(lead.Account__c)!= null)
        {
			System.debug('****** Lead is direction**********'+Lead_Direction__c);
			if(lead.Lead_Direction__c == 'Storefront')
			{
			  
			  for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			  {
				if(at.TeamMemberRole == 'Storefront Associate')
				  {
					  System.debug('******AccountId on Lead is**********'+lead.Account__c);
					  System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                      lead.OwnerId = at.UserId;
				  }
			  }
			}else if(lead.Lead_Direction__c == 'Big Deal')
			{
				
				for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			    {
				   if(at.TeamMemberRole == 'Big Deal Associate')
					{
					    System.debug('******AccountId on Lead is**********'+lead.Account__c);
						System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                        lead.OwnerId = at.UserId;
					}
			    }
			}
		}
	}

 

All Answers

s_k_as_k_a

Check the picklist value  "Big Deal Associate"  on picklist field is exactly matches with the string you have given in your apex class.  Make sure there is no leading or trailing spaces for picklist value.

brozinickrbrozinickr

I just double checked and it's not an issue with leading spaces for both the Lead Direction picklist or the TeamMemberRole string.  They match exactly.

s_k_as_k_a

Can you modify your bottom for loop in your trigger like below and try again

 

for(Lead lead : Trigger.new)
{

	 if(accountMap.containsKey(lead.Account__c) && accountMap.get(lead.Account__c).TeamMemberRole!= null)
	 {
		if(lead.Lead_Direction__c == 'Storefront' && accountMap.get(lead.Account__c).TeamMemberRole == 'Storefront Associate')
		{
			lead.OwnerId = accountMap.get(lead.Account__c).UserId;
				
		 }else if(lead.Lead_Direction__c == 'Big Deal Associate' && accountMap.get(lead.Account__c).TeamMemberRole == 'Big Deal')
		 {
			 lead.OwnerId = accountMap.get(lead.Account__c).UserId;
		 }
	 }
}

 

sushant sussushant sus
check other than storefront and big deal
if it return leadqwnerid then ur code is correct just check spelling or space while matching .....
brozinickrbrozinickr

No luck, it's still not assigning me as the Owner instead of the Big Deal Associate Account Team Member.

s_k_as_k_a

place debug statements in for loop in  your code to capture account team member and lead direction values for inserting lead.

brozinickrbrozinickr

I went ahead and tried adding some debug statements in to my code, but when I go to execute this in the system log to look at the value in debug statements, I am getting this weird error.

 

line 1, column 0: required (...)+ loop did not match anything at input 'trigger'

 

trigger OpportunityTrigger on Lead (before insert){

    List<String> accountIds = new List<String>();
    
    List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
    parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds];
    
    Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>();
    
    for(AccountTeamMember a : parentAccounts){
    
        accountMap.put(a.AccountId,a);
    }
    /*
    for(Lead lead : Trigger.new){
    
        AccountTeamMember parentAccount = accountMap.get(lead.Account__c);
        String memberRole = accountMap.get(lead.Account__c).TeamMemberRole;
        
        if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){
        
            lead.OwnerId = parentAccount.UserId;
            
        }
        
        else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){
        
            lead.OwnerId = parentAccount.UserId;
          
        }
        
        else{
        
        lead.OwnerId = lead.OwnerId;
        
        }
        
    }
    */
    for(Lead lead : Trigger.new){
    
     AccountTeamMember parentAccount = accountMap.get(lead.Account__c);

     if(accountMap.containsKey(lead.Account__c) && accountMap.get(lead.Account__c).TeamMemberRole!= null){
     
        if(lead.Lead_Direction__c == 'Storefront' && accountMap.get(lead.Account__c).TeamMemberRole == 'Storefront Associate')
        {    
            System.debug('TeamMemberRole is'+accountMap.get(lead.Account__c).TeamMemberRole);
            System.debug('LeadDirection is'+lead.Lead_Direction__c);
            lead.OwnerId = accountMap.get(lead.Account__c).UserId;
                
         }else if(lead.Lead_Direction__c == 'Big Deal Associate' && accountMap.get(lead.Account__c).TeamMemberRole == 'Big Deal')
         {   System.debug('TeamMemberRole is'+accountMap.get(lead.Account__c).TeamMemberRole);
             System.debug('LeadDirection is'+lead.Lead_Direction__c);
             lead.OwnerId = parentAccount.UserId;
         }
     }
    }
    
}

 

s_k_as_k_a

Can you post your debug log.

brozinickrbrozinickr

That's the thingIt's not even letting me execute it, it's giving me that error when I am trying to execute it anonymously in the developer console to get the debug log.

 

 

 

 

 

s_k_as_k_a

Do not excevute anonymously in the developer console. 

 

First turn on debug logs for you, then go and try to insert one lead then see the debug log for your lead insert.

 

You can turn on debug logs like this

 

setup --------> adminstrative setup------------>Monitoring------------->debuglogs

 

then click "New" button on moniterd users section and enter your name to add you as monitered user.

 

After adding you as moniterd user,  then you insert one lead from ui then navigate back to debuglogs ,here you can see your debug log for your process in debug logs section.

 

Ther you can download or view your debug log for your process.

brozinickrbrozinickr

Gotcha!  So when I submit it as a Storefront, I am seeing that it showing the Storefront values in the debug log but when I submit it as a Big Deal in the Lead Direction, it's not even printing out Big Deal in the debug log:

 

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
10:47:02.092 (92411000)|EXECUTION_STARTED
10:47:02.092 (92442000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
10:47:02.092 (92468000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
10:47:02.093 (93531000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
10:47:02.093 (93568000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
10:47:02.093 (93737000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
10:47:02.093 (93763000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
10:47:02.093 (93888000)|SYSTEM_METHOD_ENTRY|[7]|LIST<Lead>.iterator()
10:47:02.094 (94128000)|SYSTEM_METHOD_EXIT|[7]|LIST<Lead>.iterator()
10:47:02.094 (94158000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
10:47:02.094 (94189000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
10:47:02.094 (94308000)|SYSTEM_METHOD_ENTRY|[9]|LIST<String>.add(Object)
10:47:02.094 (94356000)|SYSTEM_METHOD_EXIT|[9]|LIST<String>.add(Object)
10:47:02.094 (94368000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
10:47:02.094 (94380000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
10:47:02.094 (94809000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId IN :tmpVar1
10:47:02.100 (100329000)|SOQL_EXECUTE_END|[12]|Rows:2
10:47:02.100 (100491000)|SYSTEM_METHOD_ENTRY|[16]|LIST<AccountTeamMember>.iterator()
10:47:02.100 (100624000)|SYSTEM_METHOD_EXIT|[16]|LIST<AccountTeamMember>.iterator()
10:47:02.100 (100646000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:47:02.100 (100663000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:47:02.100 (100756000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:47:02.100 (100800000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:47:02.100 (100811000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:47:02.100 (100824000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:47:02.100 (100866000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:47:02.100 (100893000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:47:02.100 (100902000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:47:02.100 (100914000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:47:02.100 (100935000)|SYSTEM_METHOD_ENTRY|[46]|LIST<Lead>.iterator()
10:47:02.100 (100954000)|SYSTEM_METHOD_EXIT|[46]|LIST<Lead>.iterator()
10:47:02.100 (100963000)|SYSTEM_METHOD_ENTRY|[46]|system.ListIterator.hasNext()
10:47:02.100 (100974000)|SYSTEM_METHOD_EXIT|[46]|system.ListIterator.hasNext()
10:47:02.101 (101011000)|SYSTEM_METHOD_ENTRY|[48]|MAP<String,AccountTeamMember>.get(Object)
10:47:02.101 (101048000)|SYSTEM_METHOD_EXIT|[48]|MAP<String,AccountTeamMember>.get(Object)
10:47:02.101 (101074000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
10:47:02.101 (101105000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
10:47:02.101 (101135000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.get(Object)
10:47:02.101 (101157000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.get(Object)
10:47:02.101 (101256000)|SYSTEM_METHOD_ENTRY|[46]|system.ListIterator.hasNext()
10:47:02.101 (101271000)|SYSTEM_METHOD_EXIT|[46]|system.ListIterator.hasNext()
10:47:02.995 (101300000)|CUMULATIVE_LIMIT_USAGE
10:47:02.995|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 9 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

10:47:02.995|CUMULATIVE_LIMIT_USAGE_END

10:47:02.101 (101347000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
10:47:02.182 (182145000)|ENTERING_MANAGED_PKG|hoopla
10:47:02.332 (332246000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
10:47:02.333 (333024000)|CODE_UNIT_FINISHED|Workflow:Lead
10:47:02.337 (337988000)|CODE_UNIT_FINISHED|TRIGGERS
10:47:02.338 (338009000)|EXECUTION_FINISHED
brozinickrbrozinickr

This is the debug log for when I selected Storefront:

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
10:45:44.238 (238751000)|EXECUTION_STARTED
10:45:44.238 (238794000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
10:45:44.238 (238822000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
10:45:44.240 (240126000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
10:45:44.240 (240165000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
10:45:44.240 (240333000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
10:45:44.240 (240362000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
10:45:44.240 (240486000)|SYSTEM_METHOD_ENTRY|[7]|LIST<Lead>.iterator()
10:45:44.240 (240767000)|SYSTEM_METHOD_EXIT|[7]|LIST<Lead>.iterator()
10:45:44.240 (240790000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
10:45:44.240 (240819000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
10:45:44.240 (240928000)|SYSTEM_METHOD_ENTRY|[9]|LIST<String>.add(Object)
10:45:44.240 (240979000)|SYSTEM_METHOD_EXIT|[9]|LIST<String>.add(Object)
10:45:44.240 (240990000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
10:45:44.241 (241001000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
10:45:44.241 (241445000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId IN :tmpVar1
10:45:44.252 (252238000)|SOQL_EXECUTE_END|[12]|Rows:2
10:45:44.252 (252361000)|SYSTEM_METHOD_ENTRY|[16]|LIST<AccountTeamMember>.iterator()
10:45:44.252 (252496000)|SYSTEM_METHOD_EXIT|[16]|LIST<AccountTeamMember>.iterator()
10:45:44.252 (252515000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:45:44.252 (252529000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:45:44.252 (252618000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:45:44.252 (252668000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:45:44.252 (252680000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:45:44.252 (252691000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:45:44.252 (252732000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:45:44.252 (252759000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
10:45:44.252 (252768000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
10:45:44.252 (252778000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
10:45:44.252 (252798000)|SYSTEM_METHOD_ENTRY|[46]|LIST<Lead>.iterator()
10:45:44.252 (252822000)|SYSTEM_METHOD_EXIT|[46]|LIST<Lead>.iterator()
10:45:44.252 (252831000)|SYSTEM_METHOD_ENTRY|[46]|system.ListIterator.hasNext()
10:45:44.252 (252841000)|SYSTEM_METHOD_EXIT|[46]|system.ListIterator.hasNext()
10:45:44.252 (252879000)|SYSTEM_METHOD_ENTRY|[48]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.252 (252919000)|SYSTEM_METHOD_EXIT|[48]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.252 (252946000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
10:45:44.252 (252983000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
10:45:44.253 (253009000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253032000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253127000)|SYSTEM_METHOD_ENTRY|[52]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253170000)|SYSTEM_METHOD_EXIT|[52]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253217000)|SYSTEM_METHOD_ENTRY|[54]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253255000)|SYSTEM_METHOD_EXIT|[54]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253282000)|SYSTEM_METHOD_ENTRY|[54]|System.debug(ANY)
10:45:44.253 (253292000)|USER_DEBUG|[54]|DEBUG|TeamMemberRole isStorefront Associate
10:45:44.253 (253297000)|SYSTEM_METHOD_EXIT|[54]|System.debug(ANY)
10:45:44.253 (253310000)|SYSTEM_METHOD_ENTRY|[55]|System.debug(ANY)
10:45:44.253 (253325000)|USER_DEBUG|[55]|DEBUG|TeamMemberRole isStorefront
10:45:44.253 (253330000)|SYSTEM_METHOD_EXIT|[55]|System.debug(ANY)
10:45:44.253 (253356000)|SYSTEM_METHOD_ENTRY|[56]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253405000)|SYSTEM_METHOD_EXIT|[56]|MAP<String,AccountTeamMember>.get(Object)
10:45:44.253 (253485000)|SYSTEM_METHOD_ENTRY|[46]|system.ListIterator.hasNext()
10:45:44.253 (253499000)|SYSTEM_METHOD_EXIT|[46]|system.ListIterator.hasNext()
10:45:44.413 (253528000)|CUMULATIVE_LIMIT_USAGE
10:45:44.413|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 11 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

10:45:44.413|CUMULATIVE_LIMIT_USAGE_END

10:45:44.253 (253678000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
10:45:44.622 (622368000)|ENTERING_MANAGED_PKG|hoopla
10:45:44.780 (780138000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
10:45:44.780 (780771000)|CODE_UNIT_FINISHED|Workflow:Lead
10:45:44.785 (785940000)|CODE_UNIT_FINISHED|TRIGGERS
10:45:44.785 (785962000)|EXECUTION_FINISHED
brozinickrbrozinickr

I just ran it again...it's weird that it's marking that it's a Storefront Associate instead of a Big Deal Associate...

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
11:10:08.115 (115615000)|EXECUTION_STARTED
11:10:08.115 (115649000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
11:10:08.115 (115673000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
11:10:08.117 (117071000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
11:10:08.117 (117120000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
11:10:08.117 (117352000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
11:10:08.117 (117389000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
11:10:08.117 (117581000)|SYSTEM_METHOD_ENTRY|[7]|LIST<Lead>.iterator()
11:10:08.117 (117923000)|SYSTEM_METHOD_EXIT|[7]|LIST<Lead>.iterator()
11:10:08.117 (117954000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
11:10:08.117 (117994000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
11:10:08.118 (118140000)|SYSTEM_METHOD_ENTRY|[9]|LIST<String>.add(Object)
11:10:08.118 (118212000)|SYSTEM_METHOD_EXIT|[9]|LIST<String>.add(Object)
11:10:08.118 (118233000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
11:10:08.118 (118252000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
11:10:08.118 (118946000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId IN :tmpVar1
11:10:08.146 (146299000)|SOQL_EXECUTE_END|[12]|Rows:2
11:10:08.146 (146547000)|SYSTEM_METHOD_ENTRY|[16]|LIST<AccountTeamMember>.iterator()
11:10:08.146 (146808000)|SYSTEM_METHOD_EXIT|[16]|LIST<AccountTeamMember>.iterator()
11:10:08.146 (146836000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
11:10:08.146 (146855000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
11:10:08.146 (146989000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
11:10:08.147 (147067000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
11:10:08.147 (147088000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
11:10:08.147 (147109000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
11:10:08.147 (147174000)|SYSTEM_METHOD_ENTRY|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
11:10:08.147 (147212000)|SYSTEM_METHOD_EXIT|[18]|MAP<String,AccountTeamMember>.put(Object, Object)
11:10:08.147 (147228000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()
11:10:08.147 (147240000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()
11:10:08.147 (147264000)|SYSTEM_METHOD_ENTRY|[47]|LIST<Lead>.iterator()
11:10:08.147 (147288000)|SYSTEM_METHOD_EXIT|[47]|LIST<Lead>.iterator()
11:10:08.147 (147299000)|SYSTEM_METHOD_ENTRY|[47]|system.ListIterator.hasNext()
11:10:08.147 (147309000)|SYSTEM_METHOD_EXIT|[47]|system.ListIterator.hasNext()
11:10:08.147 (147353000)|SYSTEM_METHOD_ENTRY|[49]|String.valueOf(Object)
11:10:08.147 (147375000)|SYSTEM_METHOD_EXIT|[49]|String.valueOf(Object)
11:10:08.147 (147396000)|SYSTEM_METHOD_ENTRY|[49]|System.debug(ANY)
11:10:08.147 (147405000)|USER_DEBUG|[49]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
11:10:08.147 (147410000)|SYSTEM_METHOD_EXIT|[49]|System.debug(ANY)
11:10:08.147 (147442000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
11:10:08.147 (147482000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.containsKey(Object)
11:10:08.147 (147510000)|SYSTEM_METHOD_ENTRY|[50]|MAP<String,AccountTeamMember>.get(Object)
11:10:08.147 (147533000)|SYSTEM_METHOD_EXIT|[50]|MAP<String,AccountTeamMember>.get(Object)
11:10:08.147 (147575000)|SYSTEM_METHOD_ENTRY|[53]|String.valueOf(Object)
11:10:08.147 (147595000)|SYSTEM_METHOD_EXIT|[53]|String.valueOf(Object)
11:10:08.147 (147608000)|SYSTEM_METHOD_ENTRY|[53]|System.debug(ANY)
11:10:08.147 (147616000)|USER_DEBUG|[53]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
11:10:08.147 (147625000)|SYSTEM_METHOD_EXIT|[53]|System.debug(ANY)
11:10:08.147 (147671000)|SYSTEM_METHOD_ENTRY|[54]|MAP<String,AccountTeamMember>.get(Object)
11:10:08.147 (147737000)|SYSTEM_METHOD_EXIT|[54]|MAP<String,AccountTeamMember>.get(Object)
11:10:08.147 (147765000)|SYSTEM_METHOD_ENTRY|[54]|System.debug(ANY)
11:10:08.147 (147776000)|USER_DEBUG|[54]|DEBUG|*********TeamMemberRole is**********Storefront Associate
11:10:08.147 (147788000)|SYSTEM_METHOD_EXIT|[54]|System.debug(ANY)
11:10:08.147 (147852000)|SYSTEM_METHOD_ENTRY|[55]|System.debug(ANY)
11:10:08.147 (147877000)|USER_DEBUG|[55]|DEBUG|*********LeadDirection is***********Big Deal
11:10:08.147 (147889000)|SYSTEM_METHOD_EXIT|[55]|System.debug(ANY)
11:10:08.147 (147945000)|SYSTEM_METHOD_ENTRY|[47]|system.ListIterator.hasNext()
11:10:08.147 (147960000)|SYSTEM_METHOD_EXIT|[47]|system.ListIterator.hasNext()
11:10:08.560 (147991000)|CUMULATIVE_LIMIT_USAGE
11:10:08.560|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 12 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

11:10:08.560|CUMULATIVE_LIMIT_USAGE_END

11:10:08.148 (148049000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
11:10:08.305 (305092000)|ENTERING_MANAGED_PKG|hoopla
11:10:08.647 (647200000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
11:10:08.656 (656595000)|CODE_UNIT_FINISHED|Workflow:Lead
11:10:08.665 (665318000)|CODE_UNIT_FINISHED|TRIGGERS
11:10:08.665 (665337000)|EXECUTION_FINISHED
s_k_as_k_a

Now its Clear. Can you query account team member records for that account. like below. I think there are more than 1 acoount team records for that account. 

 

SELECT TeamMemberRole,id, accountId FROM AccountTeamMember where  accountID ='0013000000pPKtlAAG'

 

 

brozinickrbrozinickr

Yes, that's correct, there's more than one Account Team Member for each Account.  there should be a Big Deal Associate and a Storefront Associate for each Account.

 

I switched my code to this:

 

trigger OpportunityTrigger on Lead (before insert){

    List<String> accountIds = new List<String>();
    
    List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
    //parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds];
    parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in ('0013000000pPKtl')];
    
    Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>();
    
    for(AccountTeamMember a : parentAccounts){
    
        accountMap.put(a.AccountId,a);
    }
    /*
    for(Lead lead : Trigger.new){
    
        AccountTeamMember parentAccount = accountMap.get(lead.Account__c);
        String memberRole = accountMap.get(lead.Account__c).TeamMemberRole;
        
        if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){
        
            lead.OwnerId = parentAccount.UserId;
            
        }
        
        else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){
        
            lead.OwnerId = parentAccount.UserId;
          
        }
        
        else{
        
        lead.OwnerId = lead.OwnerId;
        
        }
        
    }
    */
    
    for(Lead lead : Trigger.new)
    {
        System.debug('******AccountId on Lead is**********'+lead.Account__c);
        if(accountMap.containsKey(lead.Account__c) && accountMap.get(lead.Account__c).TeamMemberRole!= null)
       {
     
          System.debug('******AccountId on Lead is**********'+lead.Account__c);
          System.debug('*********TeamMemberRole is**********'+accountMap.get(lead.Account__c).TeamMemberRole);
          System.debug('*********LeadDirection is***********'+lead.Lead_Direction__c);
         if(lead.Lead_Direction__c == 'Storefront' && accountMap.get(lead.Account__c).TeamMemberRole == 'Storefront Associate')
         {    
           lead.OwnerId = accountMap.get(lead.Account__c).UserId;
                
         }else if(lead.Lead_Direction__c == 'Big Deal Associate' && accountMap.get(lead.Account__c).TeamMemberRole == 'Big Deal')
         {   
            lead.OwnerId = accountMap.get(lead.Account__c).UserId;
         }
       }
    }
    
}

 

 

It's still not working, here's the debug log.

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
11:42:47.100 (100637000)|EXECUTION_STARTED
11:42:47.100 (100682000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
11:42:47.100 (100711000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
11:42:47.101 (101707000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
11:42:47.101 (101746000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
11:42:47.101 (101910000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
11:42:47.101 (101939000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
11:42:47.102 (102073000)|SYSTEM_METHOD_ENTRY|[7]|LIST<Lead>.iterator()
11:42:47.102 (102324000)|SYSTEM_METHOD_EXIT|[7]|LIST<Lead>.iterator()
11:42:47.102 (102353000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
11:42:47.102 (102384000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
11:42:47.102 (102499000)|SYSTEM_METHOD_ENTRY|[9]|LIST<String>.add(Object)
11:42:47.102 (102557000)|SYSTEM_METHOD_EXIT|[9]|LIST<String>.add(Object)
11:42:47.102 (102569000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
11:42:47.102 (102582000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
11:42:47.102 (102903000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId IN ('0013000000pPKtl')
11:42:47.106 (106983000)|SOQL_EXECUTE_END|[13]|Rows:2
11:42:47.107 (107111000)|SYSTEM_METHOD_ENTRY|[17]|LIST<AccountTeamMember>.iterator()
11:42:47.107 (107249000)|SYSTEM_METHOD_EXIT|[17]|LIST<AccountTeamMember>.iterator()
11:42:47.107 (107273000)|SYSTEM_METHOD_ENTRY|[17]|system.ListIterator.hasNext()
11:42:47.107 (107289000)|SYSTEM_METHOD_EXIT|[17]|system.ListIterator.hasNext()
11:42:47.107 (107384000)|SYSTEM_METHOD_ENTRY|[19]|MAP<String,AccountTeamMember>.put(Object, Object)
11:42:47.107 (107434000)|SYSTEM_METHOD_EXIT|[19]|MAP<String,AccountTeamMember>.put(Object, Object)
11:42:47.107 (107445000)|SYSTEM_METHOD_ENTRY|[17]|system.ListIterator.hasNext()
11:42:47.107 (107458000)|SYSTEM_METHOD_EXIT|[17]|system.ListIterator.hasNext()
11:42:47.107 (107502000)|SYSTEM_METHOD_ENTRY|[19]|MAP<String,AccountTeamMember>.put(Object, Object)
11:42:47.107 (107529000)|SYSTEM_METHOD_EXIT|[19]|MAP<String,AccountTeamMember>.put(Object, Object)
11:42:47.107 (107538000)|SYSTEM_METHOD_ENTRY|[17]|system.ListIterator.hasNext()
11:42:47.107 (107550000)|SYSTEM_METHOD_EXIT|[17]|system.ListIterator.hasNext()
11:42:47.107 (107571000)|SYSTEM_METHOD_ENTRY|[48]|LIST<Lead>.iterator()
11:42:47.107 (107600000)|SYSTEM_METHOD_EXIT|[48]|LIST<Lead>.iterator()
11:42:47.107 (107611000)|SYSTEM_METHOD_ENTRY|[48]|system.ListIterator.hasNext()
11:42:47.107 (107622000)|SYSTEM_METHOD_EXIT|[48]|system.ListIterator.hasNext()
11:42:47.107 (107663000)|SYSTEM_METHOD_ENTRY|[50]|String.valueOf(Object)
11:42:47.107 (107687000)|SYSTEM_METHOD_EXIT|[50]|String.valueOf(Object)
11:42:47.107 (107707000)|SYSTEM_METHOD_ENTRY|[50]|System.debug(ANY)
11:42:47.107 (107716000)|USER_DEBUG|[50]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
11:42:47.107 (107721000)|SYSTEM_METHOD_EXIT|[50]|System.debug(ANY)
11:42:47.107 (107747000)|SYSTEM_METHOD_ENTRY|[51]|MAP<String,AccountTeamMember>.containsKey(Object)
11:42:47.107 (107788000)|SYSTEM_METHOD_EXIT|[51]|MAP<String,AccountTeamMember>.containsKey(Object)
11:42:47.107 (107815000)|SYSTEM_METHOD_ENTRY|[51]|MAP<String,AccountTeamMember>.get(Object)
11:42:47.107 (107839000)|SYSTEM_METHOD_EXIT|[51]|MAP<String,AccountTeamMember>.get(Object)
11:42:47.107 (107882000)|SYSTEM_METHOD_ENTRY|[54]|String.valueOf(Object)
11:42:47.107 (107904000)|SYSTEM_METHOD_EXIT|[54]|String.valueOf(Object)
11:42:47.107 (107915000)|SYSTEM_METHOD_ENTRY|[54]|System.debug(ANY)
11:42:47.107 (107921000)|USER_DEBUG|[54]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
11:42:47.107 (107926000)|SYSTEM_METHOD_EXIT|[54]|System.debug(ANY)
11:42:47.107 (107956000)|SYSTEM_METHOD_ENTRY|[55]|MAP<String,AccountTeamMember>.get(Object)
11:42:47.107 (107997000)|SYSTEM_METHOD_EXIT|[55]|MAP<String,AccountTeamMember>.get(Object)
11:42:47.108 (108021000)|SYSTEM_METHOD_ENTRY|[55]|System.debug(ANY)
11:42:47.108 (108029000)|USER_DEBUG|[55]|DEBUG|*********TeamMemberRole is**********Storefront Associate
11:42:47.108 (108034000)|SYSTEM_METHOD_EXIT|[55]|System.debug(ANY)
11:42:47.108 (108083000)|SYSTEM_METHOD_ENTRY|[56]|System.debug(ANY)
11:42:47.108 (108101000)|USER_DEBUG|[56]|DEBUG|*********LeadDirection is***********Big Deal
11:42:47.108 (108108000)|SYSTEM_METHOD_EXIT|[56]|System.debug(ANY)
11:42:47.108 (108157000)|SYSTEM_METHOD_ENTRY|[48]|system.ListIterator.hasNext()
11:42:47.108 (108171000)|SYSTEM_METHOD_EXIT|[48]|system.ListIterator.hasNext()
11:42:47.914 (108198000)|CUMULATIVE_LIMIT_USAGE
11:42:47.914|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 12 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

11:42:47.914|CUMULATIVE_LIMIT_USAGE_END

11:42:47.108 (108255000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
11:42:47.251 (251874000)|ENTERING_MANAGED_PKG|hoopla
11:42:47.417 (417110000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
11:42:47.417 (417828000)|CODE_UNIT_FINISHED|Workflow:Lead
11:42:47.430 (430655000)|CODE_UNIT_FINISHED|TRIGGERS
11:42:47.430 (430675000)|EXECUTION_FINISHED

 

 

s_k_as_k_a

TRy the below code . I hope code will work this time

trigger OpportunityTrigger on Lead (before insert){

   Set<Id> accountIds = new Set<Id>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
   
    Map<Id,List<AccountTeamMember>> acctToAccTeanMemsMap = new Map<Id,List<AccountTeamMember>>();
    
    for(AccountTeamMember atm : [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds])
	{
       if(acctToAccTeanMemsMap.containsKey(atm.AccountId) && acctToAccTeanMemsMap.get(atm.AccountId)!= null)
		{
            List<AccountTeamMember> accountteamMems = new List<AccountTeamMember>();
			accountteamMems = acctToAccTeanMemsMap.get(atm.AccountId);
			accountteamMems.add(atm);
			acctToAccTeanMemsMap.put(atm.AccountId,accountteamMems);
		}else
			acctToAccTeanMemsMap.put(atm.AccountId, new List<AccountTeamMember>{atm}); 
    }    
    
    for(Lead lead : Trigger.new)
    {
        System.debug('******AccountId on Lead is**********'+lead.Account__c);
        if(acctToAccTeanMemsMap.containsKey(lead.Account__c) && acctToAccTeanMemsMap.get(lead.Account__c)!= null)
        {
			if(lead.Lead_Direction__c == 'Storefront')
			{
			  for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			  {
				if(at.TeamMemberRole == 'Storefront Associate')
				  {
					  System.debug('******AccountId on Lead is**********'+lead.Account__c);
					  System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                      lead.OwnerId = at.UserId;
				  }
			  }
			}else if(lead.Lead_Direction__c == 'Big Deal Associate')
			{
				for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			    {
				   if(at.TeamMemberRole == 'Big Deal')
					{
					    System.debug('******AccountId on Lead is**********'+lead.Account__c);
						System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                        lead.OwnerId = at.UserId;
					}
			    }
			}
		}
	}
}

 

brozinickrbrozinickr

Still no luck. :(

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
13:02:45.039 (39093000)|EXECUTION_STARTED
13:02:45.039 (39136000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
13:02:45.039 (39170000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
13:02:45.040 (40271000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>(Integer)
13:02:45.040 (40316000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>(Integer)
13:02:45.040 (40583000)|SYSTEM_METHOD_ENTRY|[5]|LIST<Lead>.iterator()
13:02:45.040 (40822000)|SYSTEM_METHOD_EXIT|[5]|LIST<Lead>.iterator()
13:02:45.040 (40850000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
13:02:45.040 (40882000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
13:02:45.041 (41016000)|SYSTEM_METHOD_ENTRY|[7]|SET<Id>.add(Object)
13:02:45.041 (41046000)|SYSTEM_METHOD_EXIT|[7]|SET<Id>.add(Object)
13:02:45.041 (41056000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
13:02:45.041 (41073000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
13:02:45.041 (41651000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember 
13:02:45.045 (45592000)|SOQL_EXECUTE_END|[13]|Rows:2
13:02:45.045 (45659000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocator.iterator()
13:02:45.045 (45780000)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
13:02:45.045 (45796000)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
13:02:45.045 (45864000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocator.iterator()
13:02:45.045 (45882000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.045 (45949000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
13:02:45.045 (45975000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
13:02:45.045 (45987000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.045 (45997000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
13:02:45.046 (46010000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46030000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46039000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46048000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46097000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
13:02:45.046 (46167000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46193000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46226000)|SYSTEM_CONSTRUCTOR_ENTRY|[22]|<init>()
13:02:45.046 (46245000)|SYSTEM_CONSTRUCTOR_EXIT|[22]|<init>()
13:02:45.046 (46260000)|SYSTEM_METHOD_ENTRY|[22]|LIST<AccountTeamMember>.add(Object)
13:02:45.046 (46272000)|SYSTEM_METHOD_EXIT|[22]|LIST<AccountTeamMember>.add(Object)
13:02:45.046 (46285000)|SYSTEM_METHOD_ENTRY|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
13:02:45.046 (46299000)|SYSTEM_METHOD_EXIT|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
13:02:45.046 (46308000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46323000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46332000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46340000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46346000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
13:02:45.046 (46355000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46365000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46373000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
13:02:45.046 (46381000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46407000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
13:02:45.046 (46433000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46446000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46470000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46483000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46496000)|SYSTEM_CONSTRUCTOR_ENTRY|[17]|<init>()
13:02:45.046 (46513000)|SYSTEM_CONSTRUCTOR_EXIT|[17]|<init>()
13:02:45.046 (46539000)|SYSTEM_METHOD_ENTRY|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46559000)|SYSTEM_METHOD_EXIT|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46574000)|SYSTEM_METHOD_ENTRY|[19]|LIST<AccountTeamMember>.add(Object)
13:02:45.046 (46591000)|SYSTEM_METHOD_EXIT|[19]|LIST<AccountTeamMember>.add(Object)
13:02:45.046 (46617000)|SYSTEM_METHOD_ENTRY|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
13:02:45.046 (46638000)|SYSTEM_METHOD_EXIT|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
13:02:45.046 (46647000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46659000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
13:02:45.046 (46679000)|SYSTEM_METHOD_ENTRY|[25]|LIST<Lead>.iterator()
13:02:45.046 (46697000)|SYSTEM_METHOD_EXIT|[25]|LIST<Lead>.iterator()
13:02:45.046 (46707000)|SYSTEM_METHOD_ENTRY|[25]|system.ListIterator.hasNext()
13:02:45.046 (46720000)|SYSTEM_METHOD_EXIT|[25]|system.ListIterator.hasNext()
13:02:45.046 (46755000)|SYSTEM_METHOD_ENTRY|[27]|String.valueOf(Object)
13:02:45.046 (46776000)|SYSTEM_METHOD_EXIT|[27]|String.valueOf(Object)
13:02:45.046 (46801000)|SYSTEM_METHOD_ENTRY|[27]|System.debug(ANY)
13:02:45.046 (46810000)|USER_DEBUG|[27]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
13:02:45.046 (46817000)|SYSTEM_METHOD_EXIT|[27]|System.debug(ANY)
13:02:45.046 (46842000)|SYSTEM_METHOD_ENTRY|[28]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46864000)|SYSTEM_METHOD_EXIT|[28]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
13:02:45.046 (46887000)|SYSTEM_METHOD_ENTRY|[28]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46904000)|SYSTEM_METHOD_EXIT|[28]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
13:02:45.046 (46973000)|SYSTEM_METHOD_ENTRY|[25]|system.ListIterator.hasNext()
13:02:45.046 (46990000)|SYSTEM_METHOD_EXIT|[25]|system.ListIterator.hasNext()
13:02:45.781 (47019000)|CUMULATIVE_LIMIT_USAGE
13:02:45.781|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 10 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

13:02:45.781|CUMULATIVE_LIMIT_USAGE_END

13:02:45.047 (47068000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
13:02:45.134 (134296000)|ENTERING_MANAGED_PKG|hoopla
13:02:45.138 (138867000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
13:02:45.138 (138922000)|CODE_UNIT_FINISHED|Workflow:Lead
13:02:45.142 (142590000)|CODE_UNIT_FINISHED|TRIGGERS
13:02:45.142 (142606000)|EXECUTION_FINISHED
s_k_as_k_a

After seeing your debug lo, i understand that The if loop inside for loop did not exceute. (If you see the debug log it is upto 28 line after 28 line the loop ends. Put debug statement at line 24(above for loop) to get the map values.

 

System.debug('*****************MAp Values*********'+acctToAccTeanMemsMap.values());

brozinickrbrozinickr

Here's the debug log:

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:09:03.036 (36982000)|EXECUTION_STARTED
14:09:03.037 (37026000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
14:09:03.037 (37060000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
14:09:03.038 (38285000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>(Integer)
14:09:03.038 (38331000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>(Integer)
14:09:03.038 (38570000)|SYSTEM_METHOD_ENTRY|[5]|LIST<Lead>.iterator()
14:09:03.038 (38846000)|SYSTEM_METHOD_EXIT|[5]|LIST<Lead>.iterator()
14:09:03.038 (38875000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
14:09:03.038 (38908000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
14:09:03.039 (39028000)|SYSTEM_METHOD_ENTRY|[7]|SET<Id>.add(Object)
14:09:03.039 (39059000)|SYSTEM_METHOD_EXIT|[7]|SET<Id>.add(Object)
14:09:03.039 (39069000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
14:09:03.039 (39082000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
14:09:03.039 (39536000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember 
14:09:03.065 (65712000)|SOQL_EXECUTE_END|[13]|Rows:2
14:09:03.065 (65811000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocator.iterator()
14:09:03.065 (65975000)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
14:09:03.065 (65987000)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
14:09:03.066 (66069000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocator.iterator()
14:09:03.066 (66089000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66164000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66197000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66209000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66222000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
14:09:03.066 (66236000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66255000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66264000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66273000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66311000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
14:09:03.066 (66389000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.066 (66417000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.066 (66456000)|SYSTEM_CONSTRUCTOR_ENTRY|[22]|<init>()
14:09:03.066 (66480000)|SYSTEM_CONSTRUCTOR_EXIT|[22]|<init>()
14:09:03.066 (66496000)|SYSTEM_METHOD_ENTRY|[22]|LIST<AccountTeamMember>.add(Object)
14:09:03.066 (66507000)|SYSTEM_METHOD_EXIT|[22]|LIST<AccountTeamMember>.add(Object)
14:09:03.066 (66520000)|SYSTEM_METHOD_ENTRY|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
14:09:03.066 (66533000)|SYSTEM_METHOD_EXIT|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
14:09:03.066 (66542000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66558000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66567000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66575000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66581000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
14:09:03.066 (66590000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66601000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66609000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
14:09:03.066 (66618000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66644000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
14:09:03.066 (66671000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.066 (66685000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.066 (66712000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.066 (66725000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.066 (66748000)|SYSTEM_CONSTRUCTOR_ENTRY|[17]|<init>()
14:09:03.066 (66766000)|SYSTEM_CONSTRUCTOR_EXIT|[17]|<init>()
14:09:03.066 (66796000)|SYSTEM_METHOD_ENTRY|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.066 (66817000)|SYSTEM_METHOD_EXIT|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.066 (66830000)|SYSTEM_METHOD_ENTRY|[19]|LIST<AccountTeamMember>.add(Object)
14:09:03.066 (66848000)|SYSTEM_METHOD_EXIT|[19]|LIST<AccountTeamMember>.add(Object)
14:09:03.066 (66874000)|SYSTEM_METHOD_ENTRY|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
14:09:03.066 (66897000)|SYSTEM_METHOD_EXIT|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
14:09:03.066 (66906000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66919000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
14:09:03.066 (66942000)|SYSTEM_METHOD_ENTRY|[25]|MAP<Id,LIST<AccountTeamMember>>.values()
14:09:03.067 (67072000)|SYSTEM_METHOD_EXIT|[25]|MAP<Id,LIST<AccountTeamMember>>.values()
14:09:03.067 (67100000)|SYSTEM_METHOD_ENTRY|[25]|String.valueOf(Object)
14:09:03.067 (67205000)|SYSTEM_METHOD_EXIT|[25]|String.valueOf(Object)
14:09:03.067 (67229000)|SYSTEM_METHOD_ENTRY|[25]|System.debug(ANY)
14:09:03.067 (67238000)|USER_DEBUG|[25]|DEBUG|*****************MAp Values*********((AccountTeamMember:{AccountId=0013000000pPKtlAAG, Id=01Me0000006gYrkEAE, UserId=00530000005AAbwAAG, TeamMemberRole=Big Deal Associate}, AccountTeamMember:{AccountId=0013000000pPKtlAAG, Id=01Me0000006g4eHEAQ, UserId=00530000005E06RAAS, TeamMemberRole=Storefront Associate}))
14:09:03.067 (67251000)|SYSTEM_METHOD_EXIT|[25]|System.debug(ANY)
14:09:03.067 (67274000)|SYSTEM_METHOD_ENTRY|[27]|LIST<Lead>.iterator()
14:09:03.067 (67296000)|SYSTEM_METHOD_EXIT|[27]|LIST<Lead>.iterator()
14:09:03.067 (67307000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
14:09:03.067 (67320000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()
14:09:03.067 (67353000)|SYSTEM_METHOD_ENTRY|[29]|String.valueOf(Object)
14:09:03.067 (67372000)|SYSTEM_METHOD_EXIT|[29]|String.valueOf(Object)
14:09:03.067 (67381000)|SYSTEM_METHOD_ENTRY|[29]|System.debug(ANY)
14:09:03.067 (67386000)|USER_DEBUG|[29]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
14:09:03.067 (67392000)|SYSTEM_METHOD_EXIT|[29]|System.debug(ANY)
14:09:03.067 (67418000)|SYSTEM_METHOD_ENTRY|[30]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.067 (67442000)|SYSTEM_METHOD_EXIT|[30]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
14:09:03.067 (67467000)|SYSTEM_METHOD_ENTRY|[30]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.067 (67485000)|SYSTEM_METHOD_EXIT|[30]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
14:09:03.067 (67561000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
14:09:03.067 (67576000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()
14:09:03.580 (67611000)|CUMULATIVE_LIMIT_USAGE
14:09:03.580|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 11 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

14:09:03.580|CUMULATIVE_LIMIT_USAGE_END

14:09:03.067 (67665000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
14:09:03.155 (155000000)|ENTERING_MANAGED_PKG|hoopla
14:09:03.521 (521549000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
14:09:03.522 (522301000)|CODE_UNIT_FINISHED|Workflow:Lead
14:09:03.532 (532336000)|CODE_UNIT_FINISHED|TRIGGERS
14:09:03.532 (532350000)|EXECUTION_FINISHED
s_k_as_k_a

What is the datatype of Account__c on lead?. LookUp or text

s_k_as_k_a

Can you take debug log for below code.

trigger OpportunityTrigger on Lead (before insert){

   Set<Id> accountIds = new Set<Id>();
    
    for(Lead lead : Trigger.new){
    
        accountIds.add(lead.Account__c);    
    }
    
   
    Map<Id,List<AccountTeamMember>> acctToAccTeanMemsMap = new Map<Id,List<AccountTeamMember>>();
    
    for(AccountTeamMember atm : [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds])
	{
       if(acctToAccTeanMemsMap.containsKey(atm.AccountId) && acctToAccTeanMemsMap.get(atm.AccountId)!= null)
		{
            List<AccountTeamMember> accountteamMems = new List<AccountTeamMember>();
			accountteamMems = acctToAccTeanMemsMap.get(atm.AccountId);
			accountteamMems.add(atm);
			acctToAccTeanMemsMap.put(atm.AccountId,accountteamMems);
		}else
			acctToAccTeanMemsMap.put(atm.AccountId, new List<AccountTeamMember>{atm}); 
    }    
    
    for(Lead lead : Trigger.new)
    {
       
		
		System.debug('******AccountId on Lead is**********'+lead.Account__c);
        if(acctToAccTeanMemsMap.containsKey(lead.Account__c) && acctToAccTeanMemsMap.get(lead.Account__c)!= null)
        {
			System.debug('****** Lead is direction**********'+Lead_Direction__c);
			if(lead.Lead_Direction__c == 'Storefront')
			{
			  
			  for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			  {
				if(at.TeamMemberRole == 'Storefront Associate')
				  {
					  System.debug('******AccountId on Lead is**********'+lead.Account__c);
					  System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                      lead.OwnerId = at.UserId;
				  }
			  }
			}else if(lead.Lead_Direction__c == 'Big Deal')
			{
				
				for(AccountTeamMember at: acctToAccTeanMemsMap.get(lead.Account__c))
			    {
				   if(at.TeamMemberRole == 'Big Deal Associate')
					{
					    System.debug('******AccountId on Lead is**********'+lead.Account__c);
						System.debug('*********TeamMemberRole is**********'+at.TeamMemberRole);
                        lead.OwnerId = at.UserId;
					}
			    }
			}
		}
	}

 

This was selected as the best answer
brozinickrbrozinickr

Account__c is a lookup.  And I just created a lead and it worked! :)  Here's the debug log just in case you'd like to look.  Thank you so much for your help on this, I appreciate it!

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:09:19.031 (31911000)|EXECUTION_STARTED
15:09:19.031 (31952000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
15:09:19.031 (31982000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe0000000ChGQ|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
15:09:19.033 (33088000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>(Integer)
15:09:19.033 (33138000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>(Integer)
15:09:19.033 (33413000)|SYSTEM_METHOD_ENTRY|[5]|LIST<Lead>.iterator()
15:09:19.033 (33663000)|SYSTEM_METHOD_EXIT|[5]|LIST<Lead>.iterator()
15:09:19.033 (33697000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
15:09:19.033 (33731000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
15:09:19.033 (33874000)|SYSTEM_METHOD_ENTRY|[7]|SET<Id>.add(Object)
15:09:19.033 (33908000)|SYSTEM_METHOD_EXIT|[7]|SET<Id>.add(Object)
15:09:19.033 (33919000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
15:09:19.033 (33931000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
15:09:19.034 (34487000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select AccountId, UserId, TeamMemberRole from AccountTeamMember 
15:09:19.039 (39431000)|SOQL_EXECUTE_END|[13]|Rows:2
15:09:19.039 (39537000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocator.iterator()
15:09:19.039 (39710000)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
15:09:19.039 (39724000)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
15:09:19.039 (39815000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocator.iterator()
15:09:19.039 (39843000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.039 (39936000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
15:09:19.039 (39975000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
15:09:19.039 (39989000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40000000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
15:09:19.040 (40016000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40037000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40047000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40057000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40097000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
15:09:19.040 (40184000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.040 (40217000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.040 (40255000)|SYSTEM_CONSTRUCTOR_ENTRY|[22]|<init>()
15:09:19.040 (40279000)|SYSTEM_CONSTRUCTOR_EXIT|[22]|<init>()
15:09:19.040 (40294000)|SYSTEM_METHOD_ENTRY|[22]|LIST<AccountTeamMember>.add(Object)
15:09:19.040 (40307000)|SYSTEM_METHOD_EXIT|[22]|LIST<AccountTeamMember>.add(Object)
15:09:19.040 (40323000)|SYSTEM_METHOD_ENTRY|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
15:09:19.040 (40342000)|SYSTEM_METHOD_EXIT|[22]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
15:09:19.040 (40352000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40367000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40376000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40385000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40392000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.next()
15:09:19.040 (40402000)|SYSTEM_METHOD_ENTRY|[48]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40413000)|SYSTEM_METHOD_ENTRY|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40424000)|SYSTEM_METHOD_EXIT|[33]|LIST<AccountTeamMember>.size()
15:09:19.040 (40433000)|SYSTEM_METHOD_EXIT|[48]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40459000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.next()
15:09:19.040 (40488000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.040 (40503000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.040 (40527000)|SYSTEM_METHOD_ENTRY|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.040 (40541000)|SYSTEM_METHOD_EXIT|[15]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.040 (40558000)|SYSTEM_CONSTRUCTOR_ENTRY|[17]|<init>()
15:09:19.040 (40580000)|SYSTEM_CONSTRUCTOR_EXIT|[17]|<init>()
15:09:19.040 (40608000)|SYSTEM_METHOD_ENTRY|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.040 (40635000)|SYSTEM_METHOD_EXIT|[18]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.040 (40657000)|SYSTEM_METHOD_ENTRY|[19]|LIST<AccountTeamMember>.add(Object)
15:09:19.040 (40683000)|SYSTEM_METHOD_EXIT|[19]|LIST<AccountTeamMember>.add(Object)
15:09:19.040 (40713000)|SYSTEM_METHOD_ENTRY|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
15:09:19.040 (40743000)|SYSTEM_METHOD_EXIT|[20]|MAP<Id,LIST<AccountTeamMember>>.put(Object, Object)
15:09:19.040 (40753000)|SYSTEM_METHOD_ENTRY|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40766000)|SYSTEM_METHOD_EXIT|[13]|Database.QueryLocatorIterator.hasNext()
15:09:19.040 (40790000)|SYSTEM_METHOD_ENTRY|[25]|MAP<Id,LIST<AccountTeamMember>>.values()
15:09:19.040 (40931000)|SYSTEM_METHOD_EXIT|[25]|MAP<Id,LIST<AccountTeamMember>>.values()
15:09:19.040 (40963000)|SYSTEM_METHOD_ENTRY|[25]|String.valueOf(Object)
15:09:19.041 (41072000)|SYSTEM_METHOD_EXIT|[25]|String.valueOf(Object)
15:09:19.041 (41102000)|SYSTEM_METHOD_ENTRY|[25]|System.debug(ANY)
15:09:19.041 (41111000)|USER_DEBUG|[25]|DEBUG|*****************MAp Values*********((AccountTeamMember:{AccountId=0013000000pPKtlAAG, Id=01Me0000006gYrkEAE, UserId=00530000005AAbwAAG, TeamMemberRole=Big Deal Associate}, AccountTeamMember:{AccountId=0013000000pPKtlAAG, Id=01Me0000006g4eHEAQ, UserId=00530000005E06RAAS, TeamMemberRole=Storefront Associate}))
15:09:19.041 (41121000)|SYSTEM_METHOD_EXIT|[25]|System.debug(ANY)
15:09:19.041 (41142000)|SYSTEM_METHOD_ENTRY|[27]|LIST<Lead>.iterator()
15:09:19.041 (41170000)|SYSTEM_METHOD_EXIT|[27]|LIST<Lead>.iterator()
15:09:19.041 (41184000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
15:09:19.041 (41198000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()
15:09:19.041 (41233000)|SYSTEM_METHOD_ENTRY|[31]|String.valueOf(Object)
15:09:19.041 (41254000)|SYSTEM_METHOD_EXIT|[31]|String.valueOf(Object)
15:09:19.041 (41264000)|SYSTEM_METHOD_ENTRY|[31]|System.debug(ANY)
15:09:19.041 (41269000)|USER_DEBUG|[31]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
15:09:19.041 (41275000)|SYSTEM_METHOD_EXIT|[31]|System.debug(ANY)
15:09:19.041 (41301000)|SYSTEM_METHOD_ENTRY|[32]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.041 (41327000)|SYSTEM_METHOD_EXIT|[32]|MAP<Id,LIST<AccountTeamMember>>.containsKey(Object)
15:09:19.041 (41352000)|SYSTEM_METHOD_ENTRY|[32]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.041 (41376000)|SYSTEM_METHOD_EXIT|[32]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.041 (41429000)|SYSTEM_METHOD_ENTRY|[34]|System.debug(ANY)
15:09:19.041 (41447000)|USER_DEBUG|[34]|DEBUG|****** Lead is direction**********Big Deal
15:09:19.041 (41455000)|SYSTEM_METHOD_EXIT|[34]|System.debug(ANY)
15:09:19.041 (41511000)|SYSTEM_METHOD_ENTRY|[50]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.041 (41543000)|SYSTEM_METHOD_EXIT|[50]|MAP<Id,LIST<AccountTeamMember>>.get(Object)
15:09:19.041 (41558000)|SYSTEM_METHOD_ENTRY|[50]|LIST<AccountTeamMember>.iterator()
15:09:19.041 (41742000)|SYSTEM_METHOD_EXIT|[50]|LIST<AccountTeamMember>.iterator()
15:09:19.041 (41771000)|SYSTEM_METHOD_ENTRY|[50]|system.ListIterator.hasNext()
15:09:19.041 (41788000)|SYSTEM_METHOD_EXIT|[50]|system.ListIterator.hasNext()
15:09:19.041 (41854000)|SYSTEM_METHOD_ENTRY|[54]|String.valueOf(Object)
15:09:19.041 (41877000)|SYSTEM_METHOD_EXIT|[54]|String.valueOf(Object)
15:09:19.041 (41891000)|SYSTEM_METHOD_ENTRY|[54]|System.debug(ANY)
15:09:19.041 (41897000)|USER_DEBUG|[54]|DEBUG|******AccountId on Lead is**********0013000000pPKtlAAG
15:09:19.041 (41903000)|SYSTEM_METHOD_EXIT|[54]|System.debug(ANY)
15:09:19.041 (41919000)|SYSTEM_METHOD_ENTRY|[55]|System.debug(ANY)
15:09:19.041 (41933000)|USER_DEBUG|[55]|DEBUG|*********TeamMemberRole is**********Big Deal Associate
15:09:19.041 (41940000)|SYSTEM_METHOD_EXIT|[55]|System.debug(ANY)
15:09:19.042 (42107000)|SYSTEM_METHOD_ENTRY|[50]|system.ListIterator.hasNext()
15:09:19.042 (42126000)|SYSTEM_METHOD_EXIT|[50]|system.ListIterator.hasNext()
15:09:19.042 (42157000)|SYSTEM_METHOD_ENTRY|[50]|system.ListIterator.hasNext()
15:09:19.042 (42170000)|SYSTEM_METHOD_EXIT|[50]|system.ListIterator.hasNext()
15:09:19.042 (42180000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
15:09:19.042 (42188000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()
15:09:19.790 (42209000)|CUMULATIVE_LIMIT_USAGE
15:09:19.790|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 15 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

15:09:19.790|CUMULATIVE_LIMIT_USAGE_END

15:09:19.042 (42344000)|CODE_UNIT_FINISHED|OpportunityTrigger on Lead trigger event BeforeInsert for [new]
15:09:19.183 (183549000)|ENTERING_MANAGED_PKG|hoopla
15:09:19.334 (334355000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Lead
15:09:19.334 (334416000)|CODE_UNIT_FINISHED|Workflow:Lead
15:09:19.340 (340026000)|CODE_UNIT_FINISHED|TRIGGERS
15:09:19.340 (340045000)|EXECUTION_FINISHED