+ Start a Discussion
RDN_LHRRDN_LHR 

SOQL Join in Maps

Hi,
 
I would like to automatically assign certain records to their Account Owners on insert.  In this particular version,
I am trying to do this only when the Owner has IsActive=true in the User table.  I'm guess that while this SOQL statement is ok in real life, it doesn't work in a map.
 
 
 
Map<Id, Account> accMap = new Map<Id, Account>([select Id, OwnerId, Owner.isActive
            from Account where Id in :accSet]);
           
     
for ( Contact loopContact : Trigger.new )
 {
    
 if (accMap.get(loopContact.AccountId).isActive = true)
  { 
      loopContact.OwnerId = accMap.get(loopContact.AccountId).OwnerId;
  } 
 
    else {
 
       // do something else
  }
JimRaeJimRae
One little change and it should work:

Code:
Map<Id, Account> accMap = new Map<Id, Account>([select Id, OwnerId, Owner.isActive
            from Account where Id in :accSet]);
           
     
for ( Contact loopContact : Trigger.new )
 {
    
 if (accMap.get(loopContact.AccountId).Owner.isActive = true)
  { 
      loopContact.OwnerId = accMap.get(loopContact.AccountId).OwnerId;
  } 
 
    else {
 
       // do something else
  }