• Mostafa Agourri 8
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello everyone , 

Im creating a trigger that automate creating a team member for an account if statement but its not working , there is my Code 

public static void CreateAccountTeam(List<Account> listAccounts){
        List<AccountTeamMember> LsTeamMember = new List <AccountTeamMember>();
        List<Account> LsAccs = new List<Account>();
        system.debug('Mostafa1'+ listAccounts);
            for (Account a :listAccounts)
            {
                system.debug('mostafa2a'+ a);
                    if(a.CreatedBy.Type_role__c == 'CAINV' || a.CreatedBy.Type_role__c == 'DESK')
                {
                  AccountTeamMember tm = new AccountTeamMember();
                  tm.UserId = a.CreatedById;
                  tm.AccountId = a.Id;
                  tm.TeamMemberRole='CAINV';
                    LsTeamMember.add(tm);
                  system.debug('Mostafa3'+LsTeamMember);
                }
        }
            insert LsTeamMember;

    }

 public void handleAfterInsert(List<Account> lstAccount){
        AP01_AccountRules.CreateAccountTeam(lstAccount);

    }

there is trigger : 
if(Trigger.isAfter && Trigger.isInsert){
        system.debug('## AccountTrigger -- after insert');
        handler.handleAfterInsert(Trigger.new);
    }

can some one help me to resolve this 
Hello everyone , 

Im creating a trigger that automate creating a team member for an account if statement but its not working , there is my Code 

public static void CreateAccountTeam(List<Account> listAccounts){
        List<AccountTeamMember> LsTeamMember = new List <AccountTeamMember>();
        List<Account> LsAccs = new List<Account>();
        system.debug('Mostafa1'+ listAccounts);
            for (Account a :listAccounts)
            {
                system.debug('mostafa2a'+ a);
                    if(a.CreatedBy.Type_role__c == 'CAINV' || a.CreatedBy.Type_role__c == 'DESK')
                {
                  AccountTeamMember tm = new AccountTeamMember();
                  tm.UserId = a.CreatedById;
                  tm.AccountId = a.Id;
                  tm.TeamMemberRole='CAINV';
                    LsTeamMember.add(tm);
                  system.debug('Mostafa3'+LsTeamMember);
                }
        }
            insert LsTeamMember;

    }

 public void handleAfterInsert(List<Account> lstAccount){
        AP01_AccountRules.CreateAccountTeam(lstAccount);

    }

there is trigger : 
if(Trigger.isAfter && Trigger.isInsert){
        system.debug('## AccountTrigger -- after insert');
        handler.handleAfterInsert(Trigger.new);
    }

can some one help me to resolve this