• #24590
     ANISH KUMAR #224
    Forcetalks

    Adding account team member on account object in Salesforce

    trigger TeamMember on Account (after insert) {
    if(trigger.isinsert){
    for(account acct:trigger.new){
    if(acct.ParentId!=null && acct.VPA__c==false){
    Account Parentacct=[select id,ownerid from Account where id=:acct.ParentId limit 1];
    system.debug(Parentacct +’parentaccount’);
    Accountteammember acctmem=new Accountteammember();
    acctmem.AccountId=acct.id;
    system.debug(acct.id +’id’);
    acctmem.UserId=Parentacct.OwnerId;
    acctmem.TeamMemberRole=’Account Manager’;
    system.debug(acctmem +’accounteam’);
    insert acctmem;
    }
    }
    }
    }

    DML requires SObject or SObject list type: AccountTeamMember on line 13

    Tagged: , , , , , , , , ,

    #24670
    Salesforce | Charan Tej Charan Tej #48
    Forcetalks

    `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;
    }

    }
    }

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?