function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PappuPappu 

Test class for team member

Hi any one help me to write test class for this code? I tried but not getting enough code coverage.

 List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds];
 Map<Id, user> ObjMap = new Map<Id, user>([select id,unit, function  from user where Id IN :userIds AND IsActive=true]);
List<AccountTeamMember> updatedaccountlist = new List<AccountTeamMember>();
        for (AccountTeamMember am : accountTeamList )
        {
            if(ObjMap.containsKey(am.userId)) //Validate Account userId and Userrecord Userid are equal
            {  
                User obj = ObjMap.get(am.userId);
                AccountTeamMember teamrole =new AccountTeamMember();
                teamrole.userId = obj.User_ID_18__c;
                teamrole.AccountId= am.AccountId;
                if (obj.unit != null && obj.function != null)
                {
                    teamrole.TeamMemberRole = obj.unit +' '+ obj.function;
                }
                else 
                {
                    teamrole.TeamMemberRole = 'Unspecified';
                }
                updatedaccountlist.add(teamrole);
            }
            
        }
        
        insert updatedaccountlist;
        
Raj VakatiRaj Vakati
try this code
 
@isTest
private class addAccountTeam {

    @isTest
    static void test_checkTSGAccounTeamInsert() {
   
        List<Account> accList = new List<Account>();
        for (Integer i = 0; i < 5; i++) {
            Account newAcc = new Account(Name='Test' + i,P21_CompanyCustomer_ID__c = '1-10009' + i );
            accList.add(newAcc);
        }
        insert accList;
   
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
		String teamMemberRole = 'Account Manager';
String accountAccessLevel = 'Edit', opportunityAccessLevel = 'Edit', caseAccessLevel = 'None';

        // create the Users
        List<User> userList = new List<User>();
        for (Integer i = 0; i< 5; i++) {
            // observe the same name for Opp and TSG
            USer newUser = new User(lastname = 'Test',Alias = 'Test',TimeZoneSidKey = 'GMT',
            LocaleSidKey = 'eu_ES',EmailEncodingKey = 'ISO-8859-1',
            ProfileId = p.id,LanguageLocaleKey = 'en_US',
            userName='Test' + i + '@sdkksdhfhdsjhf.com',email='Test' + i + '@asjgdgsad.com');
            userList.add(newUser);
        }
        insert userList;
       
       
        //Create the AccountTeam
        List<AccountTeamMember> teamList = new List<AccountTeamMember>();
        For (Integer i = 0; i< 5; i++) {
        AccountTeamMember newTeam = new AccountTeamMember(AccountId = accList[i].ID,
		TeamMemberRole = 'Technical Sales',UserId = userList[i].ID);
        teamList.add(newTeam);
        }
        insert teamList;
       
        //Create the AccountTeamShare
        List<AccountShare> shareList = new List<AccountShare>();
        For (Integer i = 0; i< 5; i++) {
        AccountShare newShare = new AccountShare(AccountId = accList[i].ID,UserOrGroupId = userList[i].ID,CaseAccessLevel = 'Edit',AccountAccessLevel = 'Edit',OpportunityAccessLevel = 'Edit');
        shareList.add(newShare);
        }
        insert shareList;

    }
}

 
Raj VakatiRaj Vakati
Try this
 
@isTest
private class addAccountTeam {

    @isTest
    static void test_checkTSGAccounTeamInsert() {
   
        List<Account> accList = new List<Account>();
        for (Integer i = 0; i < 5; i++) {
            Account newAcc = new Account(Name='Test' + i,P21_CompanyCustomer_ID__c = '1-10009' + i );
            accList.add(newAcc);
        }
        insert accList;
   
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
		String teamMemberRole = 'Account Manager';
String accountAccessLevel = 'Edit', opportunityAccessLevel = 'Edit', caseAccessLevel = 'None';

        // create the Users
        List<User> userList = new List<User>();
        for (Integer i = 0; i< 5; i++) {
            // observe the same name for Opp and TSG
            USer newUser = new User(lastname = 'Test',Alias = 'Test',TimeZoneSidKey = 'GMT',
            LocaleSidKey = 'eu_ES',EmailEncodingKey = 'ISO-8859-1',
            ProfileId = p.id,LanguageLocaleKey = 'en_US',
            userName='Test' + i + '@sdkksdhfhdsjhf.com',email='Test' + i + '@asjgdgsad.com');
            userList.add(newUser);
        }
        insert userList;
       
       
        //Create the AccountTeam
        List<AccountTeamMember> teamList = new List<AccountTeamMember>();
        For (Integer i = 0; i< 5; i++) {
        AccountTeamMember newTeam = new AccountTeamMember(AccountId = accList[i].ID,
		TeamMemberRole = 'Technical Sales',UserId = userList[i].ID);
        teamList.add(newTeam);
        }
		For (Integer i = 0; i< 5; i++) {
        AccountTeamMember newTeam = new AccountTeamMember(AccountId = accList[i].ID,
		TeamMemberRole = 'Technical Sales',UserId = userList[i].ID);
        teamList.add(newTeam);
        }
		
        insert teamList;
       
        //Create the AccountTeamShare
        List<AccountShare> shareList = new List<AccountShare>();
        For (Integer i = 0; i< 5; i++) {
        AccountShare newShare = new AccountShare(AccountId = accList[i].ID,UserOrGroupId = userList[i].ID,CaseAccessLevel = 'Edit',AccountAccessLevel = 'Edit',OpportunityAccessLevel = 'Edit');
        shareList.add(newShare);
        }
		For (Integer i = 0; i< 5; i++) {
        AccountShare newShare = new AccountShare(AccountId = accList[i].ID,UserOrGroupId = userList[i].ID,CaseAccessLevel = 'Edit',AccountAccessLevel = 'Edit',OpportunityAccessLevel = 'Edit');
        shareList.add(newShare);
        }
        insert shareList;

    }
}