Activity Forums Salesforce® Discussions Adding account team member on account object in Salesforce

  • Charan Tej

    Member
    January 30, 2018 at 9:59 am

    `trigger TeamMemberTrg on Account (after insert) {
    if(trigger.isinsert){
    set parentIds = new set();
    for(account acct:trigger.new){
    if(acct.ParentId!=null && acct.VPA__c==false){
    parentIds.add(acct.parentId);
    }
    }

    if(!parentIds.isEmpty()){
    map mpAccs = new map([select id, ownerId from Account where Id in: parentIds]);
    List members = new List();
    for(account acct:trigger.new){
    if(acct.ParentId!=null && mpAccs.containsKey(acct.ParentId) && acct.VPA__c==false){
    members.add(New AccountTeamMember(AccountId = acct.id, TeamMemberRole = 'Account Manager', UserId= mpAccs.get(acct.ParentId).OwnerId));
    }
    }

    if(!members.isEmpty())
    insert members;
    }

    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos