You need to sign in to do that
Don't have an account?

Advanced Apex Specialist Superbadge - Stpe 5 Issue
Hi All,
Am facing this issue on step 5 , can any one help me complete this challenge.

Am facing this issue on step 5 , can any one help me complete this challenge.
1. Ensure that you declare following code snippet to overcome the above error
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
Challenge Not yet complete... here's what's wrong:
Ensure you verify that the constructor sets the initial size of the productsToInsert list properly.
1. Ensure that you declare following code snippet to overcome the above error
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!
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!
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
I figured it out , below link helped me
https://developer.salesforce.com/forums/?id=9060G0000005OGJQA2
Thanks
Preetam
instead of System.assertEquals(Constants.DEFAULT_ROWS ,pe.productsToInsert.size());
This is crazy. Salesforce should work on it.
public Product2Extension(ApexPages.StandardController standardController){
productsToInsert = new List<ProductWrapper>();
AddRows();
}
2) Use System.assert(productExtension.productsToInsert.size() == Constants.DEFAULT_ROWS); and System.assert(productExtension.productsToInsert.size() == Constants.DEFAULT_ROWS * 2); instead of System.assertEquals in Product2Tests Class.
@Preetham, were you able to solve the expected actual issue? The link you shared is not opening. Could you help m with the same? I am stuck for the last two days as well. It's taking the value 20 by default and not asserting successfully.
System.AssertException: Assertion Failed: Expected: 20, Actual: 10
While running unit tests the assertions pass but via 'Check Challenge', values are different and assertions are failing.
Please suggest the solution.
When checking the developer console i found that the challenge tests directly the VerifyQuantityOrdered method with :
- first these values : originalProduct.quantity_remaining__c = 0 | updatedProduct.quantity_remaining__c = 10 | QuantityOrdered = 10, so no problem here, the assertion succeeds.
- then with these values : originalProduct.quantity_remaining__c = 0 | updatedProduct.quantity_remaining__c = 10 | QuantityOrdered = 20 which causes the assertion to fail. But i don't understand what this has to do with best practices like described in the challenge error message ?
I've tried the below code to try to bypass this issue : But i received another error message when checking the challenge :I've also tried to create a new trailhead playground, upload the code then check the challenge but i received the same error message as in the begining. I cross-compared with someone's code who already passed the superbadge and i found that his code was very similar to mine, and was doing the same thing in the VerifyQuantityOrdered methode.
Does anyone have any other idea to try ?
Thank you.
I also facing same issue from long time..could you please help me to resolve this issue.
Please help me if any body resolved this issue?
Thank you!
I had a really rough time with this step for some 3-4 days but actually this step is looking out for your methods in the test class to be private as well as use the @isTest method annotation. Do try this and let me know if it worked. Cheers!
Thank you, it worked. Annotation should be
@isTest private static void
for every test method.
But it still doesn't pass !
try this:
@isTest (seeAllData=false)
private class OrderTests {
@testSetup
static void SetupTestData() {...}
@isTest private static void OrderUpdate_UnitTest() {...}
@isTest private static void OrderExtension_UnitTest() {...}
}
Probably OrderExtension_UnitTest is required for the step.
private class OrderTests {
@testSetup
static void SetupTestData(){
TestDataFactory.InsertTestData(3);
}
@isTest
private static void OrderUpdate_UnitTest(){
List<Order> orders = new List<Order>();
List<Product2> products = [ SELECT Id,Quantity_Ordered__c FROM Product2 ];
for(Order o : [ SELECT Id,Status,ActivatedDate FROM Order ]){
o.Status = Constants.ACTIVATED_ORDER_STATUS;
o.ActivatedDate = Date.today();
orders.add(o);
}
Test.startTest();
update orders;
Test.stopTest();
List<Product2> productsUpdated = [ SELECT Id,Quantity_Ordered__c FROM Product2 ];
for(Integer i=0; i<productsUpdated.size(); i++){
TestDataFactory.VerifyQuantityOrdered( products[i], productsUpdated[i], Constants.DEFAULT_ROWS );
}
}
@isTest
private static void OrderExtension_UnitTest(){
List<Order> orders = [SELECT Id,AccountId,EffectiveDate,Pricebook2Id,Status FROM Order];
ApexPages.StandardController std = new ApexPages.StandardController(orders[0]);
Test.startTest();
OrderExtension extensions = new OrderExtension(std);
extensions.First();
extensions.Next();
extensions.Previous();
extensions.Last();
extensions.GetFamilyOptions();
extensions.OnFieldChange();
extensions.SelectFamily();
Boolean previous = extensions.GetHasPrevious();
Boolean next = extensions.GetHasNext();
Integer numberPages = extensions.GetPageNumber();
Integer totalPages = extensions.GetTotalPages();
extensions.save();
Test.stopTest();
System.assert(!previous);
System.assert(!next);
System.assertEquals(1, numberPages);
System.assertEquals(1, totalPages);
}
}
Use this code for OrderTests Class then issue will be resolved.for it is resolved
The reason is the challenge is also looking for the method OrderExtension_UnitTest to be declared as private and with the @isTest annotation, although this method is not used in this challenge, but you have to declare it even with an empty body it will work.
Thanks again for your help everyone.
assertEquals will fail but a basic assert will pass the challenge
Not cool, TrailHead....
I also had an issue that was resolved using System.assert instead of System.assertEquals.
Note though, I had to use
instead of Why must it be so specific!?