• Ummul Fazaria
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am trying to create a trigger where contact description will update when account object description is updated and my code is as below: but i am getting an error "Loop must iterate over collection: Map<Id,Account>"

trigger ContactFieldUpdate on Account (after update) {
  Set<ID> setAccId = new Set<ID>();
    List<contact> lstConUpdate = new List<Contact>();
    for(Account accl : Trigger.new)
    {    
            setAccId.add(accl.id);
    }
    
    Map<ID, Account> mapAccount = new Map<ID, Account>([select id,description,(select id,description from contacts ) from account where id in :setAccId ]);
    
    for(Account acc: mapAccount){
        for(Contact con : acc.contacts){
            con.Description = acc.Description;
            lstConUpdate.add(con);
        }
    }
    
     update lstConUpdate;
        
    }