You need to sign in to do that
Don't have an account?
advanced apex superbadge error - Ensure that you create the OrderUpdate_UnitTest test method with the proper declaration and proper access modifier, to ensure best practices.
This is in Step 5 of the Superbadge. here is my test class
Can anyone tell me why I am getting that error? my tests are running fine and I have enough code coverage on the extension, the order trigger and the order helper (which is what this step is about).
What am I missing? I have tried to chang @IsTest for TestMethod, but it still doesn't work.
@isTest private class OrderTests { @TestSetup static void SetupTestData(){ TestDataFactory.InsertTestData(5); } @isTest static void OrderUpdate_UnitTest(){ //retrieve the orders saved by TestDataFactory Map<Id, Order> orders= new Map<Id, Order>([SELECT Id, Status FROM Order]); //save the original Product2 record in a map Map<Id, Product2> originalProductMap = new Map<Id, Product2>(); //Loop through a query of OrderItems related to the orders List<OrderItem> items = [SELECT Id, Product2Id, Product2.Quantity_Ordered__c, Quantity FROM OrderItem WHERE OrderId IN :orders.keySet()]; //ToDo: Populate the map with the Id of the related Product2 as the key and Product2 record as the value for ( OrderItem oi : items){ Product2 p = oi.Product2; if (!originalProductMap.containsKey(p.Id)) { originalProductMap.put(p.Id, p); } } //update the Status of the orders List<Order> updatedOrders = new List<Order>(); for (Order order : orders.values()) { order.Status = Constants.ACTIVATED_ORDER_STATUS; updatedOrders.add(order); } //get the amounts to be order for each Product //declare a map to save the Amounts for each product Map<Id, Integer> prodAmounts = new Map<Id, Integer>(); //get the aggregated amounts by product id AggregateResult[] groupedResults = [SELECT Product2Id,SUM(Product2.Quantity_Ordered__c), SUM(Quantity) FROM OrderItem WHERE Product2Id IN :originalProductMap.keySet() GROUP BY Product2Id]; for (AggregateResult ar : groupedResults) { prodAmounts.put(String.valueOf(ar.get('Product2Id')),Integer.valueOf(ar.get('expr1'))); } //update the orders in the DB update updatedOrders; //retrieve the products affected by the orders update Map<Id, Product2> updatedProductMap = new Map<Id, Product2>([SELECT id, Quantity_Ordered__c FROM Product2 WHERE id IN :originalProductMap.keySet()]); for (Product2 origProd : originalProductMap.values()) { TestDataFactory.VerifyQuantityOrdered(origProd,updatedProductMap.get(origProd.Id), prodAmounts.get(origProd.Id)); } } }
Can anyone tell me why I am getting that error? my tests are running fine and I have enough code coverage on the extension, the order trigger and the order helper (which is what this step is about).
What am I missing? I have tried to chang @IsTest for TestMethod, but it still doesn't work.
https://developer.salesforce.com/forums/?id=9060G0000005OGJQA2
Thanks for your response. I tried your code, and it is still giving me the same error