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
SFDCDevQASFDCDevQA 

Bulking Test Class

I am trying to bulk my test class and running into issues.  I finally seem to have gotten past whatever was causing my DML error (I added a limit of 200 rows) but now it's still giving me an error on the UPDATE (not insert) saying that my demo doesn't have a demo date when they all clearly do because they inserted just fine.  What totally obvious thing am I clearly missing?
Thanks,
Amanda

    static testMethod void TestDemoSpecialisttoOppTeamSL() {
        
        //inserting a user
         Map<String,ID> profiles = new Map<String,ID>();
        List<Profile> ps = [select id, name from Profile where name =
        'Standard User' or name = 'System Administrator'];
            for(Profile p : ps){
                profiles.put(p.name, p.id);
            }

OMITTING a bunch of code here that doesn't seem to be part of the issue...this is where my bulking begins.
        
        // Insert 100 Demos
    List<Demo__c> Demos = new List<Demo__c>();
    for (Integer i = 0; i < 200; i++) {
        Demo__c demo = new Demo__c();
        demo.name = 'Test Demo' + i;
        demo.Contact__c = cont[0].id;
        demo.Opportunity__c = opp.id;
        demo.demo_date__c = Date.newInstance(2020,12,01);
        demo.Sales_Rep_Notes__c = 'Testing new demo creation';
        demos.add(demo);
    }
    insert Demos;      
        // Switch to test context
        Test.startTest();
    demos = [SELECT Id, Demo_Given_By__c FROM Demo__c limit 200];    
        //update demo to include demo specialist
        for (Demo__c demo : demos) {
          demo.Demo_Given_by__c = users[4].id;
    }
    update demos;       
 
        // check that the Opportunity Team Members were created
        List<OpportunityTeammember> newOTM = [Select otm.Id From OpportunityTeamMember otm where OpportunityID = :opp.id];
        System.assertEquals(newOTM.size(),2);
                
        // Switch back to runtime context
        Test.stopTest();       
 
    }
Best Answer chosen by SFDCDevQA
Shashikant SharmaShashikant Sharma
You could user a clause Where In in: Demos in SOQL as well with above.

Like 

demos = [SELECT Id, Demo_Given_By__c FROM Demo__c Where Id in: Demos limit 200];

Thanks
Shashikant

All Answers

Shashikant SharmaShashikant Sharma
Hi Amanda,

Could you please use seeAllData = false for your test class, by this it will make sure that your query for update return only records in test context not from the organization records.

@isTest(seeAllData = false)

Thanks
Shashikant
Shashikant SharmaShashikant Sharma
You could user a clause Where In in: Demos in SOQL as well with above.

Like 

demos = [SELECT Id, Demo_Given_By__c FROM Demo__c Where Id in: Demos limit 200];

Thanks
Shashikant
This was selected as the best answer
SFDCDevQASFDCDevQA
I had to use the see all Data because earlier in the code required territories.  The Where Id in :demos was exactly what I was blanking out on.  I knew it had to be something simple that I was overlooking.  Thanks!