+ Start a Discussion
Santosh Reddy MaddhuriSantosh Reddy Maddhuri 

Advanced Apex Specialist Superbadge - Stpe 5 Issue

Hi All,

Am facing this issue on step 5 , can any one help me complete this challenge.

User-added image
Best Answer chosen by Santosh Reddy Maddhuri
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
For benefit of others here is the solution.

1. Ensure that you declare following code snippet to overcome the above error
 
public Product2Extension(ApexPages.StandardController controller) { 
       productsToInsert = new List<ProductWrapper>();
       addRows();  
    }

2. If the above code snippet did not solve, then mostly its the trailhead test data not able to validat your code.For this create another trailhead playground and copy the code of all the 5 steps and re validate the step 5.This will pass the step.

Hope this helps!

All Answers

Santosh Reddy MaddhuriSantosh Reddy Maddhuri
Here is the error
Challenge Not yet complete... here's what's wrong: 
Ensure you verify that the constructor sets the initial size of the productsToInsert list properly.
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
For benefit of others here is the solution.

1. Ensure that you declare following code snippet to overcome the above error
 
public Product2Extension(ApexPages.StandardController controller) { 
       productsToInsert = new List<ProductWrapper>();
       addRows();  
    }

2. If the above code snippet did not solve, then mostly its the trailhead test data not able to validat your code.For this create another trailhead playground and copy the code of all the 5 steps and re validate the step 5.This will pass the step.

Hope this helps!
This was selected as the best answer
Cody Maines DevCody Maines Dev
I ended up solving this error by changing my assertions. When I used System.assertEquals(controller.productsToInsert.size(),  Constants.DEFAULT_ROWS) it would not work. I changed it to System.assert(controller.productsToInsert.size() == Constants.DEFAULT_ROWS) it finally passed.
Raja Vivekanandhan 8Raja Vivekanandhan 8
I have the constructor as mentioned.
I event tried creating another play ground and have the same assertions mentioned above. 
I still get the error "Ensure you verify that the constructor sets the initial size of the productsToInsert list properly.".
Can any one help on resolving this issue? Thanks!
Preetham 345 SFDCPreetham 345 SFDC
Hi Ravi , 

I have done both the steps provided by you , but still i am not able to proceed ahead ,getting the same error upon click of check challenge 

Challenge Not yet complete... here's what's wrong: 
Ensure you verify that the constructor sets the initial size of the productsToInsert list properly.

I belive a anonymous script upon click of Check challenge button , I have debugged that as well

I still dont understand how 20 value is hardcoded  in the script up on click of Check Challenge button , Is this superbadge trail head issue ??

Execute Anonymous: Integer qtyOrdered = 10;
Execute Anonymous: Product2 originalProduct = new Product2(Quantity_Ordered__c = 0);
Execute Anonymous: Product2 updatedProduct = new Product2(Quantity_Ordered__c = qtyOrdered);
Execute Anonymous: testDataFactory.verifyQuantityOrdered( originalProduct, updatedProduct, 20 );
20:10:45.6 (6924719)|USER_INFO|[EXTERNAL]|0056A000001WgB7|developerpre@apex.com|Pacific Standard Time|GMT-07:00 20:10:45.6 (6962427)|EXECUTION_STARTED 20:10:45.6 (6968658)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex 20:10:45.6 (8132146)|SYSTEM_MODE_ENTER|false 20:10:45.6 (10455034)|SOQL_EXECUTE_BEGIN|[9]|Aggregations:0|SELECT id FROM PriceBook2 WHERE isStandard = TRUE LIMIT 1 20:10:45.6 (14239644)|SOQL_EXECUTE_END|[9]|Rows:1 20:10:45.6 (14751276)|USER_DEBUG|

[140]|DEBUG|@@@@@@@@@@@@@@@@@originalProduct.Quantity_Ordered__c  0 [141]|DEBUG|@@@@@@@@@@@@@@@@@updatedProduct.Quantity_Ordered__c  10 [142]|DEBUG|@@@@@@@@@@@@@@@@@qtyOrdered  20
[143]|System.AssertException: Assertion Failed: Expected: 20, Actual: 10


Please kindly some help , it has been two days appoximately i have been fighting on this , thanks in advance .



Thanks 
Preetam
Preetham 345 SFDCPreetham 345 SFDC
Hi Ravi , 

I figured it out , below link helped me 

https://developer.salesforce.com/forums/?id=9060G0000005OGJQA2

Thanks 
Preetam
AshesAshes
I am able to solve this issue by adding System.assert(pe.productsToInsert.size() == Constants.DEFAULT_ROWS);
instead of System.assertEquals(Constants.DEFAULT_ROWS ,pe.productsToInsert.size());

This is crazy. Salesforce should work on it.