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
Emilien Guichard 40Emilien Guichard 40 

Advanced Apex Specialist Superbadge - step 5 - Access to pricebook id in Constants class

Hi everybody,

I'm experimenting an issue on the Advanced Apex Specialist Superbadge at the step 5, when I run the tests Product2Tests and OrderTest the SetupTestData is not able to get the pricebook id.
I have a "System.QueryException: List has no rows for assignment to SObject" error.

Here is the Constants class :
 
public class Constants {
   public static final Integer DEFAULT_ROWS = 5;
   public static final String SELECT_ONE = System.Label.Select_One;
   public static final String INVENTORY_LEVEL_LOW = System.Label.Inventory_Level_Low;
   public static final List <Schema.PicklistEntry> PRODUCT_FAMILY = Product2.Family.getDescribe().getPicklistValues();
   public static final String DRAFT_ORDER_STATUS = 'Draft';
   public static final String ACTIVATED_ORDER_STATUS = 'Activated';
   public static final String INVENTORY_ANNOUNCEMENTS = 'Inventory Annoncements';
   public static final String ERROR_MESSAGE = 'An error has occured, please take a screenshot with the URL and send it to IT.';
   public static final Id STANDARD_PRICEBOOK_ID = [SELECT Id From Pricebook2 WHERE IsStandard = true].Id;
}
and the test class:
@isTest
private class OrderTests {
    
    @testSetup
    static void SetupTestData() {
	    TestDataFactory.InsertTestData(Constants.DEFAULT_ROWS);
    }
}
Thanks a lot for your help on this.
Have a good day !