• Pankaj S.
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I'm getting the following error on Advanced Apex Specialist Superbadge - Step 5.  Any ideas please?
User-added image

Here is the current code segments:

VerifyQuantityOrdered
Public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
       	decimal tot = (originalProduct.Quantity_Ordered__c + qtyOrdered);
        
            system.debug('OldVQ ' + originalProduct.Quantity_Ordered__c);
            system.debug('NewVQ ' + updatedProduct.Quantity_Ordered__c);
            system.debug('QTYVQ ' + qtyOrdered);
        
        system.assertEquals(updatedProduct.Quantity_Ordered__c,tot);     
    }
OrderTests
@isTest
private with sharing class OrderTests {

    @testSetup 
    private static void SetupTestData (){    
    	TestDataFactory.InsertTestData(5);   
    } 

    @isTest
    private static void OrderUpdate_UnitTest (){
        Test.startTest();
    	
        List<Order> OrderList = [select id, name, status from order];

        For (Order ordrec : OrderList) {
            OrderItem oirec = [select id, Pricebookentry.product2Id from orderitem where orderid=:ordrec.id];
			Product2 oldprodrec = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c 
                            	FROM Product2 where id =: oirec.Pricebookentry.product2Id  limit 1];
            ordrec.status = constants.ACTIVATED_ORDER_STATUS;
            update ordrec;
            OrderItem oirec1 = [select id, Pricebookentry.product2Id from orderitem where orderid=:ordrec.id];
			Product2 newprodrec = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c 
                            	FROM Product2 where id =: oirec1.Pricebookentry.product2Id  limit 1]; 
            system.debug('Old ' + oldprodrec.Quantity_Ordered__c);
            system.debug('New ' + newprodrec.Quantity_Ordered__c);
            system.debug('QTY ' + constants.DEFAULT_ROWS);
            TestDataFactory.VerifyQuantityOrdered(oldprodrec,newprodrec,constants.DEFAULT_ROWS);
        }
        Test.stopTest();          
    }
}
Product2Tests
@isTest  (seeAllData=false)
private with sharing class Product2Tests {

    /**
     * @name product2Extension_UnitTest
     * @description UnitTest for product2Extension
    **/
    @isTest
    private static void Product2Extension_UnitTest(){
// Set-up user
        String uniqueUserName = 'standarduser' + DateTime.now().getTime() + '@testorg.com';
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
        	EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
        	LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName=uniqueUserName);

        System.runAs(u) {
        
// When a user first visits the page, there should be multiple rows displayed on the screen. 
// Assert that the size of the productsToInsert list is equal to the DEFAULT_ROWS constant.
//		Test.StartTest(); 
        	Product2 prod = new Product2(name='Test',isActive=true);
        	ApexPages.StandardController stdc = new ApexPages.StandardController(prod);
        	Product2Extension p2x = new Product2Extension(stdc);        
       		System.assertEquals(Constants.DEFAULT_ROWS, p2x.productsToInsert.size());
//		Test.StopTest();  

// When the Add button is clicked, an additional set of rows should be added, 
// so assert that the size of the productsToInsert ** list is double **DEFAULT_ROWS after the button is clicked once. 
//        Test.StartTest();
        	p2x.addRows();
        	System.assertEquals(Constants.DEFAULT_ROWS * 2, p2x.productsToInsert.size());
//		Test.StopTest();          

// Next, test the Save button. Verify that populated rows are saved and unpopulated rows are not saved. 
// Loop through the rows in the productsToInsert list and populate the values of the first 5 records, 
// and then simulate clicking the Save button. Verify that the button worked by asserting that only 5 products were saved.
		integer x = 0; 
        for (Product2Extension.ProductWrapper PTI : p2x.productsToInsert){
            pti.productrecord.name='TESTPRODUCT ' + x;
            pti.productRecord.IsActive = true;
            pti.productRecord.Initial_Inventory__c = 20;
            pti.productRecord.Family = Constants.PRODUCT_FAMILY[0].getValue();           
            pti.pricebookEntryRecord.UnitPrice = 10;
            
        	x++; if (x==5) {break;}
        }

//        Test.startTest();
        	p2x.save();
//        Test.stopTest();
        List<Product2> createdProducts = [SELECT Id FROM Product2];
        System.assertEquals(5, createdProducts.size());

// plus some more test areas        
        p2x.GetFamilyOptions();
        p2x.GetInventory();

    }
    }
}


 
Cross-posting here from the Trailhead forum, where I'm working on the Lightning Components Framework SuperBadge. We're implementing LDS on a page, but NOT using force:hasRecordId. Instead, we're dynamically setting an aura:attribute, and then referencing it in the LDS parameter for recordId. I've been researching this for hours, but all the reference docs and Trailhead modules assume the case where you're using the implicit recordId on the page. No examples I can find where they're setting the recordId and then forcing the reload.

In this case, the id attribute is successfully being set, but LDS isn't loading the record. The error message says: The onBoatSelected handler in the BoatDetails controller must force Lightning Data Service to load the specified record, using logic in the controller.

In the controller, I'm using a reloadRecord command: component.find("service").reloadRecord() where "service" is the aura:id for the force:recordData element.

Is there some other command required to get the LDS to load the record?

Here's the component markup with the force:recordData info:
<aura:attribute name="id" type="String"/>
    <aura:attribute name="boat" type="Boat__c"/>
    <aura:attribute name="boatSimple" type="Boat__c"/>
    <aura:attribute name="recordError" type="String"/>

    <aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}"/>

    <force:recordData aura:id="service"
                      recordId="{!v.id}"
                      mode="VIEW"
                      fields=  "Id,
                                Name,
                                Description__c,
                                Price__c, Length__c,
                                Contact__r.Name,
                                Contact__r.Email,
                                Contact__r.HomePhone,
                                BoatType__r.Name,
                                Picture__c"
                      targetRecord="{!v.boat}"
                      targetFields="{!v.boatSimple}"
                      targetError="{!v.recordError}"
                      recordUpdated="{!c.onRecordUpdated}" />
Am I screwing up something in the markup?