• Tripti Nirmal Gupta
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Class.Constants: line 11, column 1
Class.Product2Extension.AddRows: line 11, column 1
Class.Product2Extension.<init>: line 7, column 1
Class.Product2Tests.Product2Extension_UnitTest: line 14, column 1

@isTest (seeAllData=false)
private class Product2Tests {

    /**
     * @name product2Extension_UnitTest
     * @description UnitTest for product2Extension
    **/
    static TestMethod void Product2Extension_UnitTest(){
        Test.startTest();
        PageReference pageRef = Page.Product2New;
        Test.setCurrentPage(pageRef);
        Product2 prod = new Product2(Name = 'Test Product', isActive=true);     
           ApexPages.StandardController stdctrl = new ApexPages.StandardController(prod);
        Product2Extension ext = new Product2Extension(stdctrl);
        System.assertEquals(Constants.DEFAULT_ROWS, ext.productsToInsert.size());        
            
        ext.addRows();
        System.assertEquals(Constants.DEFAULT_ROWS * 2, ext.productsToInsert.size());
        
        for (Integer i = 0; i < 5; i++) {
            Product2Extension.ProductWrapper wrapper = ext.productsToInsert[i];
            
            Product2 testProduct = new Product2();
            testProduct.Name = 'Test Product ' + i;
            testProduct.IsActive = true;
            testProduct.Initial_Inventory__c = 20;
            testProduct.Family = Constants.PRODUCT_FAMILY[0].getValue();
            wrapper.productRecord = testProduct;
            
            PricebookEntry testEntry = new PricebookEntry();
            testEntry.IsActive = true;
            testEntry.UnitPrice = 10;
            wrapper.pricebookEntryRecord = testEntry;
        }
        ext.save();
        Test.stopTest();
        
        List<Product2> createdProducts = [SELECT Id from Product2
                                          WHERE name like 'Test Product%'];
        System.assertEquals(5, createdProducts.size());      
    }
}

/**
 * @name TestDataFactory
 * @description Contains methods to construct and/or validate commonly used records
**/
public with sharing class TestDataFactory {

    /**
     * @name ConstructCollaborationGroup
     * @description
    **/
    public static CollaborationGroup ConstructCollaborationGroup(){
        //ToDo: Ensure this method returns a single Chatter CollaborationGroup
        //    whose Name starts with 'TEST' followed by the INVENTORY_ANNOUNCEMENTS constant
        //    and configured so anyone can join, see and post updates.
        
        CollaborationGroup cg = new CollaborationGroup();
        cg.Name = 'Test'+Constants.INVENTORY_ANNOUNCEMENTS;
        cg.CollaborationType = 'Public';
        return cg;
    }
    

    /**
     * @name CreateProducts
     * @description Constructs a list of Product2 records for unit tests
    **/
    public static List<Product2> ConstructProducts(Integer cnt){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Product2 records
        //  with all the required fields populated
        //  and IsActive = true
        //  an Initial Inventory set to 10
        //  and iterating through the product family picklist values throughout the list.
        List<Product2> prodList = new List<Product2>();
        List<Schema.PicklistEntry> pleList = Constants.PRODUCT_FAMILY;      
        for (Integer i=0; i< cnt; i++){
            Integer n = math.mod(i,pleList.size());
            Product2 prod = new Product2();
            prod.Name = 'Test Product ' + pleList[n].getValue() + ' ' + i;
            prod.IsActive = true;
            prod.Initial_Inventory__c = 10;
            prod.Family = pleList[n].getValue();
            prodList.add(prod);
        }
        return prodList;
    }

    /**
     * @name CreatePricebookEntries
     * @description Constructs a list of PricebookEntry records for unit tests
    **/
    public static List<PricebookEntry> ConstructPricebookEntries(List<Product2> prods){
        //ToDo: Ensure this method returns a corresponding list of PricebookEntries records
        //  related to the provided Products
        //  with all the required fields populated
        //  and IsActive = true
        //  and belonging to the standard Pricebook
        
        List<PriceBookEntry> pbeList = new List<PriceBookEntry>();        
        for (Product2 prod : prods){
            PriceBookEntry pbe = new PriceBookEntry();
            pbe.IsActive = true;
            pbe.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            pbe.Product2Id = prod.Id;
            pbe.UnitPrice = 100;
            pbeList.add(pbe);
        }
        return pbeList;
    }
    /**
     * @name CreateAccounts
     * @description Constructs a list of Account records for unit tests
    **/
    public static List<Account> ConstructAccounts(Integer cnt){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Account records
        //  with all of the required fields populated.
        List<Account> acctList = new List<Account>();     
        for (Integer i=0; i< cnt; i++){
            Account acct = new Account();
            acct.Name = 'Test Acct ' + i;
            acctList.add(acct);
        }
        return acctList;
    }

    /**
     * @name CreateContacts
     * @description Constructs a list of Contact records for unit tests
    **/
    public static List<Contact> ConstructContacts(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Contact records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Contact> contList = new List<Contact>();
        
        for (Integer i = 0; i < cnt; i++ ){
            Contact cont = new Contact();
            cont.LastName = 'Test Cont ' + i;
            cont.AccountId = accts[i].Id;
            contList.add(cont);
        }
        return contList;
    }

    /**
     * @name CreateOrders
     * @description Constructs a list of Order records for unit tests
    **/
    public static List<Order> ConstructOrders(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Order records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Order> ordList = new List<Order>();     
        for (Integer i=0; i<cnt; i++){
            Order ord = new Order();
            ord.Name = accts[i].Name + ' Test Order ' + i;
            ord.EffectiveDate = System.today();
            ord.AccountId = accts[i].Id;
            ord.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            ord.Status = Constants.DRAFT_ORDER_STATUS;
            ordList.add(ord);
        }
        return ordList;
    }

    /**
     * @name CreateOrderItems
     * @description Constructs a list of OrderItem records for unit tests
    **/
    public static List<OrderItem> ConstructOrderItems(integer cnt, list<pricebookentry> pbes, list<order> ords){
        //ToDo: Ensure this method returns a list of size cnt of OrderItem records
        //  related to the provided Pricebook Entries
        //  and related to the provided Orders
        //  with all of the required fields populated.
        //  Hint: Use the DEFAULT_ROWS constant for Quantity as it will be used in the next challenge
        List<OrderItem> ordItemList = new List<OrderItem>();
        
        for (Integer i=0; i< cnt; i++){
            OrderItem ordItem = new OrderItem();
            ordItem.OrderId = ords[i].Id;
            ordItem.Quantity = Constants.DEFAULT_ROWS;
            ordItem.PricebookEntryId = pbes[i].Id;
            ordItem.UnitPrice = pbes[i].UnitPrice;
            ordItemList.add(ordItem);
        }
        return ordItemList;
    }

    /**
     * @name SetupTestData
     * @description Inserts accounts, contacts, Products, PricebookEntries, Orders, and OrderItems.
    **/
 
    public static void InsertTestData(Integer cnt){
        //ToDo: Ensure this method calls each of the construct methods
        //  and inserts the results for use as test data.
        
        CollaborationGroup cg = ConstructCollaborationGroup();
        insert cg;
        List<Product2> prodList = ConstructProducts(cnt);
        insert prodList;
        List<PricebookEntry> pbeList = ConstructPricebookEntries(prodList);
        insert pbeList;
        List<Account> acctList = ConstructAccounts(cnt);
        insert acctList;
        List<Contact> contList = ConstructContacts(cnt, acctList);
        insert contList;
        List<Order> ordList = ConstructOrders(cnt, acctList);
        insert ordList;
        List<OrderItem> ordItemList = ConstructOrderItems(cnt, pbeList, ordList);
        insert ordItemList;
        
        /*
        delete cg;
        delete ordItemList;
        delete ordList;
        delete pbeList;
        delete prodList;       
        delete contList;
        delete acctList;
        */
    }
    
    public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered){
        System.assertEquals(originalProduct.Quantity_Ordered__c + qtyOrdered, updatedProduct.Quantity_Ordered__c);
        
    }

    
}

 
Class.Constants: line 11, column 1
Class.Product2Extension.AddRows: line 11, column 1
Class.Product2Extension.<init>: line 7, column 1
Class.Product2Tests.Product2Extension_UnitTest: line 14, column 1

@isTest (seeAllData=false)
private class Product2Tests {

    /**
     * @name product2Extension_UnitTest
     * @description UnitTest for product2Extension
    **/
    static TestMethod void Product2Extension_UnitTest(){
        Test.startTest();
        PageReference pageRef = Page.Product2New;
        Test.setCurrentPage(pageRef);
        Product2 prod = new Product2(Name = 'Test Product', isActive=true);     
           ApexPages.StandardController stdctrl = new ApexPages.StandardController(prod);
        Product2Extension ext = new Product2Extension(stdctrl);
        System.assertEquals(Constants.DEFAULT_ROWS, ext.productsToInsert.size());        
            
        ext.addRows();
        System.assertEquals(Constants.DEFAULT_ROWS * 2, ext.productsToInsert.size());
        
        for (Integer i = 0; i < 5; i++) {
            Product2Extension.ProductWrapper wrapper = ext.productsToInsert[i];
            
            Product2 testProduct = new Product2();
            testProduct.Name = 'Test Product ' + i;
            testProduct.IsActive = true;
            testProduct.Initial_Inventory__c = 20;
            testProduct.Family = Constants.PRODUCT_FAMILY[0].getValue();
            wrapper.productRecord = testProduct;
            
            PricebookEntry testEntry = new PricebookEntry();
            testEntry.IsActive = true;
            testEntry.UnitPrice = 10;
            wrapper.pricebookEntryRecord = testEntry;
        }
        ext.save();
        Test.stopTest();
        
        List<Product2> createdProducts = [SELECT Id from Product2
                                          WHERE name like 'Test Product%'];
        System.assertEquals(5, createdProducts.size());      
    }
}

/**
 * @name TestDataFactory
 * @description Contains methods to construct and/or validate commonly used records
**/
public with sharing class TestDataFactory {

    /**
     * @name ConstructCollaborationGroup
     * @description
    **/
    public static CollaborationGroup ConstructCollaborationGroup(){
        //ToDo: Ensure this method returns a single Chatter CollaborationGroup
        //    whose Name starts with 'TEST' followed by the INVENTORY_ANNOUNCEMENTS constant
        //    and configured so anyone can join, see and post updates.
        
        CollaborationGroup cg = new CollaborationGroup();
        cg.Name = 'Test'+Constants.INVENTORY_ANNOUNCEMENTS;
        cg.CollaborationType = 'Public';
        return cg;
    }
    

    /**
     * @name CreateProducts
     * @description Constructs a list of Product2 records for unit tests
    **/
    public static List<Product2> ConstructProducts(Integer cnt){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Product2 records
        //  with all the required fields populated
        //  and IsActive = true
        //  an Initial Inventory set to 10
        //  and iterating through the product family picklist values throughout the list.
        List<Product2> prodList = new List<Product2>();
        List<Schema.PicklistEntry> pleList = Constants.PRODUCT_FAMILY;      
        for (Integer i=0; i< cnt; i++){
            Integer n = math.mod(i,pleList.size());
            Product2 prod = new Product2();
            prod.Name = 'Test Product ' + pleList[n].getValue() + ' ' + i;
            prod.IsActive = true;
            prod.Initial_Inventory__c = 10;
            prod.Family = pleList[n].getValue();
            prodList.add(prod);
        }
        return prodList;
    }

    /**
     * @name CreatePricebookEntries
     * @description Constructs a list of PricebookEntry records for unit tests
    **/
    public static List<PricebookEntry> ConstructPricebookEntries(List<Product2> prods){
        //ToDo: Ensure this method returns a corresponding list of PricebookEntries records
        //  related to the provided Products
        //  with all the required fields populated
        //  and IsActive = true
        //  and belonging to the standard Pricebook
        
        List<PriceBookEntry> pbeList = new List<PriceBookEntry>();        
        for (Product2 prod : prods){
            PriceBookEntry pbe = new PriceBookEntry();
            pbe.IsActive = true;
            pbe.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            pbe.Product2Id = prod.Id;
            pbe.UnitPrice = 100;
            pbeList.add(pbe);
        }
        return pbeList;
    }
    /**
     * @name CreateAccounts
     * @description Constructs a list of Account records for unit tests
    **/
    public static List<Account> ConstructAccounts(Integer cnt){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Account records
        //  with all of the required fields populated.
        List<Account> acctList = new List<Account>();     
        for (Integer i=0; i< cnt; i++){
            Account acct = new Account();
            acct.Name = 'Test Acct ' + i;
            acctList.add(acct);
        }
        return acctList;
    }

    /**
     * @name CreateContacts
     * @description Constructs a list of Contact records for unit tests
    **/
    public static List<Contact> ConstructContacts(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Contact records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Contact> contList = new List<Contact>();
        
        for (Integer i = 0; i < cnt; i++ ){
            Contact cont = new Contact();
            cont.LastName = 'Test Cont ' + i;
            cont.AccountId = accts[i].Id;
            contList.add(cont);
        }
        return contList;
    }

    /**
     * @name CreateOrders
     * @description Constructs a list of Order records for unit tests
    **/
    public static List<Order> ConstructOrders(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Order records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Order> ordList = new List<Order>();     
        for (Integer i=0; i<cnt; i++){
            Order ord = new Order();
            ord.Name = accts[i].Name + ' Test Order ' + i;
            ord.EffectiveDate = System.today();
            ord.AccountId = accts[i].Id;
            ord.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            ord.Status = Constants.DRAFT_ORDER_STATUS;
            ordList.add(ord);
        }
        return ordList;
    }

    /**
     * @name CreateOrderItems
     * @description Constructs a list of OrderItem records for unit tests
    **/
    public static List<OrderItem> ConstructOrderItems(integer cnt, list<pricebookentry> pbes, list<order> ords){
        //ToDo: Ensure this method returns a list of size cnt of OrderItem records
        //  related to the provided Pricebook Entries
        //  and related to the provided Orders
        //  with all of the required fields populated.
        //  Hint: Use the DEFAULT_ROWS constant for Quantity as it will be used in the next challenge
        List<OrderItem> ordItemList = new List<OrderItem>();
        
        for (Integer i=0; i< cnt; i++){
            OrderItem ordItem = new OrderItem();
            ordItem.OrderId = ords[i].Id;
            ordItem.Quantity = Constants.DEFAULT_ROWS;
            ordItem.PricebookEntryId = pbes[i].Id;
            ordItem.UnitPrice = pbes[i].UnitPrice;
            ordItemList.add(ordItem);
        }
        return ordItemList;
    }

    /**
     * @name SetupTestData
     * @description Inserts accounts, contacts, Products, PricebookEntries, Orders, and OrderItems.
    **/
 
    public static void InsertTestData(Integer cnt){
        //ToDo: Ensure this method calls each of the construct methods
        //  and inserts the results for use as test data.
        
        CollaborationGroup cg = ConstructCollaborationGroup();
        insert cg;
        List<Product2> prodList = ConstructProducts(cnt);
        insert prodList;
        List<PricebookEntry> pbeList = ConstructPricebookEntries(prodList);
        insert pbeList;
        List<Account> acctList = ConstructAccounts(cnt);
        insert acctList;
        List<Contact> contList = ConstructContacts(cnt, acctList);
        insert contList;
        List<Order> ordList = ConstructOrders(cnt, acctList);
        insert ordList;
        List<OrderItem> ordItemList = ConstructOrderItems(cnt, pbeList, ordList);
        insert ordItemList;
        
        /*
        delete cg;
        delete ordItemList;
        delete ordList;
        delete pbeList;
        delete prodList;       
        delete contList;
        delete acctList;
        */
    }
    
    public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered){
        System.assertEquals(originalProduct.Quantity_Ordered__c + qtyOrdered, updatedProduct.Quantity_Ordered__c);
        
    }

    
}

 
Hi 
I am doing Superbadge Advanced Apex Specialist. I have completed 7 steps successfully. I am doing development in developer console. 
When I am clicking on check challenge on step 8 I am getting below error
User-added image

As all other chalenges are already completed how can i fix the issue because i am unable to retake those steps again (I am not getting any option to check chalange for completed chalenges). I am also not having previous code as I am doing development in developer console.

I am ready to retake all changes again but how can I do it without creating other trailhead account.