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
Ramesh GuduruRamesh Guduru 

TestClientHelper -test class failed

I am new to salesforce,could you please assist me,i am getting errror while running these below test class.
(error message :-System.LimitException: Too many SOQL queries: 101) 

class name:-ClientHelper
test class name:-TestClientHelper

i have attached both class & test class
PFA.

Thanks 
class name:-ClientHelper
**************************
/**********************************************************************
/**
 *  Class Name      ClientHelper
 *  @Author         Sivarajan (Siva)
 *  @Version        1.0 
 *  @Creation Date  05/25/2011
 *  @Release        
 *  @Purpose
 *                  i)  Reassigning the client Ownership to "MPG ADMIN" Once a client is inserted
 *                  ii) Adding Owner to Client team
 *Goutham Tatineni
 6/25/2012 : Made an enhancment to not include Data manager User in the client team.
***********************************************************************/

public without sharing class ClientHelper
{
    /** Instance for TeamAssignmentController  */
    static TeamAssignmentController assignmentObj;
    
    /** 
     * Method which is used to initiate Data stewardship process like
     * Changing ownership to "MPG ADMIN", Adding the client owner to client team,
     * 
     * @param 01  
     *              List of new Accounts to be inserted/updated
     * @param 02
     *              Map of new Accounts to be inserted/updated
     * @param 03
     *              true if trigger event is 'Insert'
     * 
     */
    public static void automateDSProcess(List<Account> newAccounts,
                                           Map<Id,Account> newAccountMap,
                                           boolean isInsert) {
        /** If trigger event is insertion then call the 
         * addClientTeamMember method  
         */
        if(isInsert == true) {
            addClientTeamMember(newAccounts,newAccountMap);
        }
    }
    
    
    /** 
     * Method which is used for Changing ownership to "MPG ADMIN" and  
     * Adding the client owner to client team,
     *
     * @param 01  
     *              List of new Accounts to be inserted/updated
     * @param 02
     *              Map of new Accounts to be inserted/updated
     */
    public static void addClientTeamMember(List<Account> newAccounts,
                                           Map<Id,Account> newAccountMap) {
        /* List which has Accounts to reassign */
        List<Account> reassignAccsList = new List<Account>();
        
        /* Map which is used to store user details */
        Map<Id,User> usersMap = new Map<Id,User>();
        
        /* List to store client owner Ids */
        List<Id> ownerIds = new List<Id>();
        
        /** 
           List of Account Ids where the Account owner needs 
         * to add to client team 
         */
        List<Account> accIdsToReassign = new List<Account>();
        
         /* to get Id of MPG admin user */
        User MpgAdmin = getMPGADMINDetails();
        
        for (Account acc : newAccounts) {
            Account account = new Account(Id = acc.Id,OwnerId = MpgAdmin.Id);
            reassignAccsList.add(account);
            ownerIds.add(acc.OwnerId);
        }
        
        /** 
           call the method getOwners to get the owner information like profile,
         * status(Active/inActive)and Id
         */
        usersMap = getOwners(OwnerIds);
        
        /* Reassigning client ownership to "MPG ADMIN" */
        if (reassignAccsList.size() > 0) {
            assignmentObj = new TeamAssignmentController();
            update reassignAccsList;
        }   
            
        /** 
         * Adding the user to Client team After a client is created.
         * Clients which owned by "System Admin(L3)" won't be added to client team
         */
        for (Account reAssignedAcc : newAccounts) {
            /* Adding to client team if a user is active and not related to L3 */
            if (MpgAdmin != null && usersMap.get(reAssignedAcc.OwnerId).ProfileId != MpgAdmin.ProfileId && usersMap.get(reAssignedAcc.OwnerId).ProfileId != '00e30000001YDfG'
                    && usersMap.get(reAssignedAcc.OwnerId).IsActive == true) {
                addAccountTeamMember(reAssignedAcc.Id,reAssignedAcc.OwnerId);
            }       
        }
    }
    

    
    /* Method which is used to get information of the MPG ADMIN user */ 
    public static User getMPGADMINDetails()
    {
        User MpgAdmin = [select Id,ProfileId from User where 
                         firstname =: 'MPG' and lastname =: 'ADMIN'];
        return  MpgAdmin;
    }
    
    /* Method which is used to get owner details */
    public static Map<Id,User> getOwners(List<Id> accOwnerIds)
    {
        Map<Id,User> usersMap = new Map<Id,User>([select Id,Name,ProfileId,
                                                  IsActive from user where 
                                                  Id in: accOwnerIds]); 
        return usersMap;    
    }
    
    /* Method which is used to add the Team member to the client team */
    public static void addAccountTeamMember(Id accId,Id userId)
    {
        assignmentObj.createNewAssignmentNewAssignment(
        new AccountTeamMember(AccountId = accId,TeamMemberRole
                              = 'Client Representative - Sales',
        UserId = userId));
    }

} // End of Class

********************************

Test class name :-TestClientHelper

/**
 *  Class Name      TestClientHelper
 *  @Author         Sivarajan (Siva)
 *  @Version        1.0 
 *  @Creation Date  05/31/2011
 *  @Release        -----
 *  @Purpose
 *                  Test Class for ClientHelper Apex class 
 *
***********************************************************************/
@isTest
private class TestClientHelper{
    private static Account AccforDSAutomation =null;
    private static Account AccforDSAutomation1 =null;
    private static Account newUltAccforDSAutomation = null;
    private static Account ultAccforDSAutomation = null;
    private static List<User> usrList = new List<User>();
    private static List<Account> accountList = new List<Account>();
    private static Profile ClientTeamMgrProfile;
    private static Profile SystemAdmin;
    
    
    private static List<Opportunity> optyAccforDSAutomation= new List<Opportunity>();
    
    /* Method which is used to get profiles data*/
    public static void getProfile() {
        if (ClientTeamMgrProfile  == null) {
            ClientTeamMgrProfile  = [select id from profile where name='Sales Manager'];
        }
        if (SystemAdmin  == null) {
            SystemAdmin  = [select id from profile where name='System Administrator'];
        }    
    }
    
    /* Method which is used to get users data*/
    public static void getUsers() {
            
        usrList = new List<User>();
        //SD: The environment is dynamic
        String[] environment = Userinfo.getUserName().split('@');
        for (integer i=0;i<2;i++) {
            User u = new User();
            u.FirstName=i+'DSTestFirstName1';
            u.Lastname=i+'DSTestlastname1';
            u.alias = 'Tst';
            u.email=i+ 'DSTestFirstName1.DSTestlastname1@mpg.com';
            if(i == 0)
                u.profileid = ClientTeamMgrProfile.Id;
            if(i == 1)
               u.profileid = SystemAdmin.Id;
            u.username= u.FirstName+u.Lastname+'@'+environment[1];
            u.emailencodingkey='UTF-8';
            u.languagelocalekey='en_US';
            u.localesidkey='en_US';
            u.timezonesidkey='America/Los_Angeles';
           // u.LOB_Region__c = 'MP - NA';
            u.Country ='USA';
            u.CompanyName = 'Manpower';
            u.Brand__c = 'ManpowerGroup';
            u.Region__c = 'Corporate';
            u.Sub_Region__c = 'Corporate';
            usrList.add(u);
        }
        
        if(usrList.size()> 0)
         //Test.startTest();
            insert usrList;
         //Test.stopTest(); 
    }
    
    
    /* Method which is used to insert sample Accounts */ 
    public static void getAccounts() {    
       
        if (ultAccforDSAutomation== null) {
            ultAccforDSAutomation= new Account(name = 'ultAccforDSAutomation',
                                               BillingCity ='ultAccforDSAutomationTestCity',
                                               BillingCountry ='ultAccforDSAutomationCountry',
                                               BillingStreet ='ultAccforDSAutomationSt',
                                               BillingPostalCode ='536768',
                                               phone = '010101');
           // Test.startTest();
            insert ultAccforDSAutomation;
            //Test.stopTest(); 
        }
        if (AccforDSAutomation== null) {
            AccforDSAutomation = new Account(name = 'AccforDSAutomation',
                                             BillingCity = 'DSAutomationTestCity', 
                                             BillingCountry ='DSAutomationTestCountry',
                                             BillingStreet ='DSAutomationSt', 
                                             BillingPostalCode ='536767',
                                             Ultimate_Parent_Client__c = ultAccforDSAutomation.Id,
                                             phone = '020202',
                                             OwnerId = usrList[0].Id);
            accountList.add(AccforDSAutomation );
        }
        if (AccforDSAutomation1== null) {
            AccforDSAutomation1= new Account(name = 'AccforDSAutomation1',
                                             BillingCity = 'AccforDSAutomation1TestCity', 
                                             BillingCountry ='AccforDSAutomation1TestCountry',
                                             BillingStreet ='AccforDSAutomation1St', 
                                             BillingPostalCode ='536876',
                                             phone = '010101',
                                             OwnerId = usrList[1].Id);
            accountList.add(AccforDSAutomation1);
        }
        if(accountList.size() > 0) {
          // Test.startTest();
            insert accountList;
           //Test.stopTest();
            
           
        }
         
    }    
    
    
    /* Test method to cover the code for the method of 
     *  Apex class 'ClientHelper' :
     * Method "addClientTeamMember"
     * */ 
    static testmethod void clientHelperTestmethod()
    {
    
        getProfile();
        getUsers();
        getAccounts();
     
        /*Checking whether the Ownership of Account is reassigned to "MPG ADMIN".*/
        System.assertEquals([select Id,Owner.Name from Account where 
                             Id =: AccforDSAutomation.Id].Owner.Name,'MPG ADMIN');
        List<AccountTeamMember> ATM = [Select AccountId,id,UserId,TeamMemberRole,
                                       Account.Name From AccountTeamMember 
                                       where AccountId =: AccforDSAutomation.Id];
        /* Checking whether the client Owner(Non System Admin) is added to Client team. */
        System.assertEquals(ATM.size() > 0, true);
        List<AccountTeamMember> ATM1 = [Select AccountId,id,UserId,TeamMemberRole,
                                       Account.Name From AccountTeamMember 
                                       where AccountId =: AccforDSAutomation1.Id];
        /* Checking whether the client Owner(System Admin - L3) is not added to Client team. */
        System.assertEquals(ATM1.size() == 0, true);
        /* Checking the role of the inserted client team member. */
        System.assertEquals(ATM[0].TeamMemberRole, 'Client Representative - Sales');
        
        Client_Financials__c cf = new Client_Financials__c();
        cf.Client__c = ATM[0].AccountId;
        //Test.startTest();
        insert cf;
        //Test.stopTest(); 
       ClientTeamAssignmentHelper cs = new ClientTeamAssignmentHelper();
       cs.newAccountTeamMembers(ATM1);
       cs.createClientFinancialShareList(ATM);
       cs.deleteAccountTeamMembers(ATM);
       cs.deleteClientFinancialShare(ATM);
      
    } 
    
} //End of test class
pconpcon
As stated in the other posts, your tests are structured in a way that does not act like a real interaction with your code.  I would recommend reading over this article [1] and split your test code up to only test a single section of your class wrapped in a start/stop test.

[1] http://blog.deadlypenguin.com/blog/testing/strategies/