You need to sign in to do that
Don't have an account?

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();
}
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();
}
Like
demos = [SELECT Id, Demo_Given_By__c FROM Demo__c Where Id in: Demos limit 200];
Thanks
Shashikant
All Answers
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
Like
demos = [SELECT Id, Demo_Given_By__c FROM Demo__c Where Id in: Demos limit 200];
Thanks
Shashikant