Friday, March 14, 2014

Enable account team member 
follow navigation  setup==>customize==>account====>Account teams .
once you enable this accountteam member object is added to related list of account.
2) create one check box VPA on account object.
now the requirement is:

create one record in account (call parent record) mention VPA enable and don't select parent look up field.
create  one more record in account(call child) uncheck VPA and select (parent record) as parent for this child record using look up.
here VPA is enable means that record is parent other wise it's a child record...

Need to be achieve:
1) once you create a child record then owner of parent record should be add to child   related accountteam member.(parent owner should be insert as accounteam meber to child)
2) if you change the owner in parent it should replace the old owner with new onwer.


Answer :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;

trigger AccTrigger1 on Account (after update) {
      List<AccountTeamMember> atms=new List<AccountTeamMember>();
      List<Id> ids=new List<Id>();
    for(Account a:Trigger.old)
    {
      if(a.VPA__c==true)
      {
       List<Account> childs=[SELECT id FROM Account where parentid=:a.id];
          for(Account childacc:childs)
          {
               ids.add(childacc.id);
          }
        atms=[SELECT AccountId,TeamMemberRole,UserId FROM AccountTeamMember where AccountId IN:ids ];
        for(Account a1:Trigger.new)
        {
         
             Account newoi=[SELECT OwnerId FROM Account where id=:a1.id];
              for(AccountTeamMember atm:atms)
              {
                   AccountTeamMember newatm=new  AccountTeamMember();
                   newatm.UserId=newoi.OwnerId;
                   newatm.TeamMemberRole=atm.TeamMemberRole;
                   newatm.AccountId=atm.AccountId;
                   insert newatm;
                   delete atm;
              }
        
         }
      }
    }
    
    
}



No comments:

Post a Comment