• YongChen
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

The following code gives me different results when run it in test class.
Pricebook2[] standardPB = [Select Id From Pricebook2 where IsStandard = true];
System.debug('standardPB = '+standardPB.size());

When include this in test class, it gives me: "standardPB = 0" where in Execute Anonymous, it gives me "standardPB = 1". 

I have the following code in my trigger, which gives me "List index out of bounds" when running test class.
String standardPBId = [Select Id From Pricebook2 where IsStandard = true][0].Id;
Could someone explain it?

Thanks,
 
Hi,

The following code gives me different results when run it in test class.
Pricebook2[] standardPB = [Select Id From Pricebook2 where IsStandard = true];
System.debug('standardPB = '+standardPB.size());

When include this in test class, it gives me: "standardPB = 0" where in Execute Anonymous, it gives me "standardPB = 1". 

I have the following code in my trigger, which gives me "List index out of bounds" when running test class.
String standardPBId = [Select Id From Pricebook2 where IsStandard = true][0].Id;
Could someone explain it?

Thanks,