3

The following is my test class, and I am getting the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PriceBookEntryUpdate: execution of AfterInsert on PriceBookEntryUpdate. How do I deal with another trigger causing my trigger problems? I thought I could take the test class from PriceBook and insert it into my mine, but to no avail.. Is this error telling the truth or could there be underlying problems?

@isTest
private class AutoPopulateSampleTest{
static testMethod void updateResponsibleforEVBBuildMethod1(){

  Product2 prod2 = new Product2();
  prod2.Name='TestProduct';
  prod2.IsActive=True;
  prod2.AE_Text__c='TestText';
  prod2.Item_number__c='TestNumber';
  prod2.AE2__c = '005E0000000RYQBIA4';
  prod2.Business_Unit__c ='Nissan';
  prod2.Item_class__c ='CK';     
  prod2.PME_Text__c='Michael'; 
  insert prod2;

  Sampling__c s= new Sampling__c();
  s.Name='TestEVB';
  s.Product__c = prod2.id;
  s.Quantity_of_Samples__c =12;
  //s.Responsible_for_EVB_Build1__c=prod2.AE2__c;
  insert s;


  }

  static testMethod void updateResponsibleforEVBBuildMethod2(){
  Product2 prod = new Product2();
  prod.Name='TestProduct';
  prod.IsActive=True;
  prod.Item_number__c='TestNumber';
  prod.AE_Text__c=null;
  prod.AE2__c = '005E0000000RYQBIA4';
  prod.Business_Unit__c ='Nissan';
  prod.Item_class__c ='CK';     
  prod.PME_Text__c='Michael'; 
  insert prod;

  Sampling__c s= new Sampling__c();
  s.Name='TestEVB';
  s.Product__c = prod.id;
  s.Quantity_of_Samples__c =23;

  insert s;

  }



  }

Trigger.PriceBookEntryUpdate: line 42, column 1
15:26:20.657 (9548317000)|CUMULATIVE_LIMIT_USAGE
15:26:20.657|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 3 out of 100
  Number of query rows: 1468 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

15:26:20.657|CUMULATIVE_LIMIT_USAGE_END

15:26:23.548 (9548396000)|CODE_UNIT_FINISHED|PriceBookEntryUpdate on Product2 trigger event AfterInsert for [01tM0000003IPst]
15:26:23.552 (9552102000)|DML_END|[14]
15:26:23.552 (9552201000)|EXCEPTION_THROWN|[14]|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PriceBookEntryUpdate: execution of AfterInsert

caused by: System.QueryException: List has no rows for assignment to SObject

Trigger.PriceBookEntryUpdate: line 42, column 1: []
15:26:23.553 (9553859000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PriceBookEntryUpdate: execution of AfterInsert

caused by: System.QueryException: List has no rows for assignment to SObject
2
  • Do you have more information about the error? Which trigger is causing it and maybe a line number? Can you check your debug logs please? We need to see what's happening in the trigger so that we can work out why you're getting the error while executing the test methods... Commented Mar 27, 2014 at 22:16
  • I added (SeeAllData=True) and it has gone away, did this fix it or just suppress it? Also I updated my post. The trigger that is failing I never touched, and have to look into what it actually does.
    – EricSSH
    Commented Mar 27, 2014 at 22:41

1 Answer 1

5

By the looks of it, there must be a code in your trigger that is trying to create new or update a product's pricebook entry.

When you don't use the annotation SeeAllData=true, your test class doesn't have access to the existing data in your instance. It only has access to whatever records you are creating in your test methods. In this case, you are inserting a product but when your trigger runs it looks for the product's pricebook entry and can not create/update it because it doesn't have access to the pricebooks.

At this point creating pricebooks in your test methods is not supported

"Inserting a pricebook entry for a product isn’t feasible from a test since the standard pricebook isn’t accessible and can’t be created in a running test. Also, inserting a pricebook entry for a custom pricebook isn’t supported since this requires defining a standard pricebook. For such situations, annotate your test method with IsTest(SeeAllData=true) so that your test can access organization data."

Quoted text from here - which leaves you with only 1 option, you answered it yourself - adding the annotation SeeAllData=true which will allow your test methods to get access to existing data including the pricebooks

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .