You need to sign in to do that
Don't have an account?
Shubham Nandwana
Superbadge Advanced Apex Specialist : Error
Hello,
I am facing a problem with challenge 5 of the Superbadge. Error is:
Challenge Not yet complete... here's what's wrong:
Ensure that you perform a query to verify the Save button works.
I have saved the 5 records by populating them and trying to work on the save button but unable to catch the error.
Below is my code of Product2Tests...Any help is appreciated.
@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);
ApexPages.StandardController controller =new Apexpages.StandardController(new Product2());
Product2Extension ext = new Product2Extension(controller);
ext.addRows();
ext.save();
System.assertEquals(Product2Extension.productsToInsert.size(), Constants.DEFAULT_ROWS);
//if(addValue.equals('Add'))
//System.assertEquals(Product2Extension.productsToInsert.size(), 2*Constants.DEFAULT_ROWS);
Integer i=0;
for(Product2Extension.ProductWrapper pr: Product2Extension.productsToInsert){
if (String.isBlank(pr.productRecord.Name) || pr.productRecord.Name==null){
pr.productRecord.Name='Product'+i;
}
if(String.isBlank(pr.productRecord.Family) || pr.productRecord.Family==null ){
pr.productRecord.Family='Side';
}
if(pr.productRecord.IsActive==false){
pr.productRecord.IsActive=true;
}
if(pr.productRecord.Initial_Inventory__c==null){
pr.productRecord.Initial_Inventory__c=10;
}
i++;
}
PageReference p=ext.save();
System.assertEquals(Product2Extension.productsToInsert.size(), 5);
System.debug(Product2Extension.productsToInsert.size());
Test.stopTest();
}
}
I am facing a problem with challenge 5 of the Superbadge. Error is:
Challenge Not yet complete... here's what's wrong:
Ensure that you perform a query to verify the Save button works.
I have saved the 5 records by populating them and trying to work on the save button but unable to catch the error.
Below is my code of Product2Tests...Any help is appreciated.
@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);
ApexPages.StandardController controller =new Apexpages.StandardController(new Product2());
Product2Extension ext = new Product2Extension(controller);
ext.addRows();
ext.save();
System.assertEquals(Product2Extension.productsToInsert.size(), Constants.DEFAULT_ROWS);
//if(addValue.equals('Add'))
//System.assertEquals(Product2Extension.productsToInsert.size(), 2*Constants.DEFAULT_ROWS);
Integer i=0;
for(Product2Extension.ProductWrapper pr: Product2Extension.productsToInsert){
if (String.isBlank(pr.productRecord.Name) || pr.productRecord.Name==null){
pr.productRecord.Name='Product'+i;
}
if(String.isBlank(pr.productRecord.Family) || pr.productRecord.Family==null ){
pr.productRecord.Family='Side';
}
if(pr.productRecord.IsActive==false){
pr.productRecord.IsActive=true;
}
if(pr.productRecord.Initial_Inventory__c==null){
pr.productRecord.Initial_Inventory__c=10;
}
i++;
}
PageReference p=ext.save();
System.assertEquals(Product2Extension.productsToInsert.size(), 5);
System.debug(Product2Extension.productsToInsert.size());
Test.stopTest();
}
}
Please check with below code which might help you with the above issue. Hope this helps.
Kindly mark this as solved if the information was helpful.
Thanks,
Nagendra
All Answers
Please check with below code which might help you with the above issue. Hope this helps.
Kindly mark this as solved if the information was helpful.
Thanks,
Nagendra
Hi Nagendra,
Thank you so much for your answer.
I have completed the challenge. Just added the below query in my code and it worked well
List<Product2> queryResults=[Select Name,IsActive,Initial_Inventory__c from Product2 where Initial_Inventory__c=15 and IsActive= true ];
I cannot verify your answer as the challenge is completed but I think it will work fine.
Thank you once again.