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
Dman100Dman100 

test coverage not processing bulk update branch

Can anyone help troubleshoot why my test coverage code is not testing a bulk update?
 
Here is my test coverage code:
 
Code:
static testMethod void testOpportunityOwnerRoleClass() 
 {
  // Create a new opportunity to test
  Opportunity o = new Opportunity(Ownerid='00540000000o1y6AAA',Name='Test Opportunity Owner Role Trigger',CloseDate=Date.newInstance(2008,12,31),StageName='Prospecting');
  insert o;
  // Check if owner role field has been set to updated with owner role
  System.assert(true, [Select Owner_Role__c from Opportunity WHERE ownerid = '00540000000o1y6AAA']);
  //System.assert(true, [Select Owner_Role__c from Opportunity WHERE ownerid = '00570000000sTcH']);
 }
 
 static Opportunity createNOpportunities(Integer n) {
 
 
  Opportunity opp = new Opportunity(
   ownerid = '00540000000o1y6AAA',
   Name = 'Bulk Opportunity Test',      
   StageName = 'Prospecting',     
   CloseDate = System.Today());
  
  insert opp;
  
  return opp;
 }
 
 
 public static testMethod void testBulkOpportunities() {
  
  Opportunity o = createNOpportunities(numOpportunities);
  o.StageName = 'Qualification';
  update o;
  
  Integer i = 0;
  for (Opportunity op : [Select Owner_Role__c from Opportunity WHERE ownerid = : o.ownerid])
  {
   System.assertEquals('SVP, Sales & Marketing',op.owner_role__c);
   i++;
  }
 }

 
I'm trying to loop thru multiple opportunities where a field has been updated and assert that each opportunity with a specific ownerid is set correctly?
 
I'm having problems looping thru all opportunities created in the bulk test?
 
Currently, my test coverage code is 67%.  I need another 8% to deploy.
 
Please help.
Thankk you.


Message Edited by Dman100 on 09-02-2008 11:18 PM

Message Edited by Dman100 on 09-03-2008 09:58 AM
Dman100Dman100

Will someone please help?

MikeGoelzerMikeGoelzer
Hi Dman,

The routine createNOpportunities() never references its argument 'n'.  It unconditionally creates one Opportunity.  I think you meant something more like this:

Code:
static Opportunity[] createNOpportunities(Integer n) {
  List<Opportunity> oppArr = new List<Opportunity>();
  for(integer i=0; i<n; ++i) {
    Opportunity opp = new Opportunity(
    ownerid = '00540000000o1y6AAA',
    Name = 'Bulk Opportunity Test',      
    StageName = 'Prospecting',     
    CloseDate = System.Today());
    oppArr.add(opp);
  }
  insert oppArr;
  return oppArr;
}

P.S.  All triggers are bulk now, so not sure that this test is necessary.  Post your trigger code?

MikeGoelzerMikeGoelzer
specifically:  you can probably eliminate any alternatives to the "bulk update branch" mentioned in the subject of this thread