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
srkSFsrkSF 

Advanced Apex Specialist Superbadge Step 9

Hi All,
I am getting 0% coverage in 3 classes,OrderExtension,OrderTrigger,OrderHelper.
My Tests are all passing but getting NullPointer Exception
in below code line highlighted.I dont know where I am doing mistake.
How do I correct this Error?
Please help!!!!
Thanks in Advance.

Product2Tests 
-----------------------------------------------------------
@isTest (seeAllData=false)
private class Product2Tests {
    
    /**
* @name product2Extension_UnitTest
* @description UnitTest for product2Extension
**/
    static TestMethod void Product2Extension_UnitTest(){
        
        PageReference pageRef = page.Product2New;
        Product2 prod = new Product2(Name='test', isActive= true);
        ApexPages.StandardController controller = new ApexPages.StandardController(prod);
        Test.startTest();
        Product2Extension ext = new Product2Extension(controller);
        System.assertEquals(Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        ext.addRows();
        System.assertEquals(2*Constants.DEFAULT_ROWS, ext.productsToInsert.size());
        
        for(Integer i=0; i< Constants.DEFAULT_ROWS; i++) {
            
            Product2 newProduct = new Product2(Name='Product'+i, Initial_Inventory__c = 10, isActive=true, family= Constants.PRODUCT_FAMILY.get(math.mod(i,4)).getValue());
            ext.productsToInsert.get(i).productRecord = newProduct;
            
            PriceBookEntry entry = new PriceBookEntry(UnitPrice = 100, isActive=true);
            ext.productsToInsert.get(i).pricebookEntryRecord = entry;
            
        }
        ext.save();
        ext.GetFamilyOptions();
        ext.GetInventory();
        List<Product2> selectedProd = [Select id from Product2];
        System.assertEquals(Constants.DEFAULT_ROWS, selectedProd.size());
        Test.stopTest();
    }
    
    static TestMethod void Product2Trigger_UnitTest() {
        try{
        Test.startTest();
        Product2 newProduct = new Product2();
        newProduct.Name = 'Test';
        newProduct.Family = 'Dessert';
        newProduct.IsActive = true;
        newProduct.Quantity_Ordered__c = 5;
        newProduct.Initial_Inventory__c = 10;
        insert newProduct;
        
        CollaborationGroup c = new CollaborationGroup();
        c.Name = 'TEST' + Constants.INVENTORY_ANNOUNCEMENTS;
        c.Description = 'Description';
        c.CollaborationType = 'Public';
        insert c;
        
        newProduct.Quantity_Ordered__c=96;
        update newProduct;
        Test.stopTest();
        }catch(Exception e){
            System.debug('Exception has occurred '+e);
        }
    } 
    
}
srkSFsrkSF
Overall Code Coverage is 57%
User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)

can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.Hope above information helps.

Please mark as Best Answer so that it can help others in future.

Thanks,