0

Below is my Test class code and when I run the test class I am coming across this error

System.LimitException: Too many query rows: 50001

Stack Trace Class.Testclass_StagingShippingAddressHandler.Test_ShippingAddressHandlerMethod: line 126, column 1

Below is my code can anyone say why and whats the issue

@istest(SeeAllData=true)
Public class Testclass_StagingShippingAddressHandler{
    Public static testMethod void Test_ShippingAddressHandlerMethod(){
        
        Profile pId =[Select id from Profile where name = :'System Administrator'];
        Profile pId1 =[Select id from Profile where name = :'Outside Sales'];  
        List<User> usList = new List<user>();
        User u=new User();
        u.LastName='Test';
        u.Alias='testuser';
        u.Email='test.user@stemcell.com';
        u.Username='user.test@stemcell.com';
        u.CommunityNickname='UserA';
        //Inserting a Role 
        UserRole r = new UserRole(DeveloperName = 'MyCustomRole', Name = 'My Role');
        insert r;
        u.EmailEncodingKey='ISO-8859-1';
        u.TimeZoneSidKey='America/Los_Angeles';
        u.LocaleSidKey='en_US';
        u.LanguageLocaleKey='en_US';
        u.ProfileId = pId.Id;  
        insert u;            
        System.runAs(u){
            User u1=new User();
            u1.LastName='Test1';
            u1.Alias='tuser1';
            u1.Email='test.user1@stemcell.com';
            u1.Username='test.user1@stemcell.com';
            u1.CommunityNickname='UserB';
            //Inserting a Role 
            UserRole r1 = new UserRole(DeveloperName = 'CustomRole', Name = 'Rep Role');
            insert r1;
            u1.EmailEncodingKey='ISO-8859-1';
            u1.TimeZoneSidKey='America/Los_Angeles';
            u1.LocaleSidKey='en_US';
            u1.LanguageLocaleKey='en_US';
            u1.ProfileId = pId.Id;              
            insert u1; 
            integer batchSize = 200;
            
            //Inserting recordtypes
            RecordType RT = [select id from RecordType where name ='Location' and sobjecttype = 'Territory_Component__c']; 
            RecordType RT_cust = [select id from RecordType where name ='Customer' and sobjecttype = 'Territory_Component__c']; 
            RecordType RT_exp = [select id from RecordType where name ='Export' and sobjecttype = 'Territory_Component__c'];
            RecordType RT_Par= [select id from RecordType where name ='Parent' and sobjecttype = 'Territory_Component__c']; 
            
            //Inserting Territory
            Territory__c territory = new Territory__c();
            territory.name = 'CAWESTCA';
            territory.Fiscal_Year__c = '2016';
            territory.Active__c=true;
            insert territory;
            
            //Inserting a Territory Component
            Territory_Component__c TC = new Territory_Component__c();
            TC.SoldInCountry__c = 'AUSTRALIA';
            TC.SoldInTerritoryId__c = TERRITORY.ID;
            TC.State__c = 'ACT';
            TC.Country__c ='AUSTRALIA';
            insert TC;
            
            //Inserting a Territory Component
            Territory__c territory1 = Test_CustomObjectUtil.createTerritory('USCASTEST',false);
            insert territory1;
            List<Territory_Component__c> terrCompList = new List<Territory_Component__c>();
            Territory_Component__c territoryComponent1 = Test_CustomObjectUtil.createTerritoryComponentLocation(territory1.Id, RT.Id, 'UNITED STATES', 'CA','9999',false);    
            Territory_Component__c territoryComponent2 = Test_CustomObjectUtil.createTerritoryComponentLocation(territory1.Id, RT.Id, 'UNITED STATES', 'CA',Null,false);    
            Territory_Component__c territoryComponent3 = Test_CustomObjectUtil.createTerritoryComponentLocation(territory1.Id, RT.Id, 'UNITED STATES', Null,Null,false);    
            //Territory_Component__c territoryComponent4 = Test_CustomObjectUtil.createTerritoryComponentExport(territory1.Id, RT_exp.Id, NUll,'UNITED STATES', false);    
            terrCompList.add(territoryComponent1);
            terrCompList.add(territoryComponent2);
            terrCompList.add(territoryComponent3);
            //terrCompList.add(territoryComponent4);
            insert terrCompList;
            
            //Test retrieval of reps for one territory
            Sales_Territory_Mapping__c stmFSALM = Test_CustomObjectUtil.createSalesTerritoryMapping(u1.Id, 'FSALM', territory1.Id);
            Sales_Territory_Mapping__c stmFSALCS = Test_CustomObjectUtil.createSalesTerritoryMapping(u1.Id, 'FSALCS', territory1.Id);
            stmFSALCS.Account_Owner__c = true;
            update stmFSALCS;
            
            //Inserting a Custom setting record
            /*  Switch_Fiscal_year__c SFY = new Switch_Fiscal_year__c();
SFY.Name ='Switch Fiscal year';
SFY.Current_Fiscal_year__c = '2020';
SFY.Staging_Year__c = '2021';
insert SFY;
SFY.Staging_Year__c = '2022';
update SFY; */
            
            //Inserting Shipping Address record
            List<Shipping_Address__c >ShipAdList =  new List<Shipping_Address__c >();
            Shipping_Address__c ShipAd = new Shipping_Address__c();
            ShipAd.Name = 'CAWEST';
            ShipAd.Country__c='CANADA';
            ShipAd.State__c='BC';
            insert ShipAd;             
            ShipAd.Territory__c = 'CAWESTCA';
            update ShipAd;
            ShipAdList.add(ShipAd); 
            
            //Inserting Staging Shipping Address record
            List<Shipping_Address__c >ShipAdList1 =  new List<Shipping_Address__c >();
            Shipping_Address__c ShipAd1 = new Shipping_Address__c();
            ShipAd.Name = 'CAWEST';
            ShipAd.Country__c='CANADA';
            ShipAd.State__c='BC';
            insert ShipAd1;             
            ShipAd.Staging_Territory__c = 'CAWESTCA';
            update ShipAd1;
            ShipAdList.add(ShipAd); 
            
            
            /*
//Inserting Shipping Address record
Shipping_Address__c ShipAd1 = new Shipping_Address__c();
ShipAd1.Name = 'CAWEST';
ShipAd1.Country__c='CANADA';
ShipAd1.State__c='BC';
insert ShipAd1;             
ShipAd.Territory__c = 'CAWESTCA';
update ShipAd1;
ShipAdList.add(ShipAd1); 
*/
            Set<String> testSet = new Set<String>();
            List<Int360_Master_Queue_Stage__c> queueList = [SELECT Reference_Value__c
                                                            FROM Int360_Master_Queue_Stage__c];
            Set<String> referenceSet = new Set<String>();
            for(Int360_Master_Queue_Stage__c queue : queueList) {
                referenceSet.add(queue.Reference_Value__c);
            }
            for(String id : testSet) {
                System.assert(referenceSet.contains(id));
            }
            
            
            
        }   
    }
}
1
  • If the posted answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Mar 1 '17 at 21:02
6

The problem is that you're using @isTest(SeeAllData=true) combined with an unlimited query: [SELECT Reference_Value__c FROM Int360_Master_Queue_Stage__c];.

Preferably, you should remove the SeeAllData attribute, so that you'll be isolated from your live data.

1
  • Okay I will try to work with no (SeeAllData=true) Annotation.
    – user31302
    Dec 23 '16 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy