You need to sign in to do that
Don't have an account?
Mukund Shrivastava
Challenge Not yet complete... here's what's wrong: Ensure that the Visualforce page is displayed when a use clicks the New button on the Product object
I am not able to resolve this error of advanced apex specialist challenge #2. Can anyone help?
Sorry for this issue you are encountering.
Please follow the below tips using which you can pass the step 2 of the advanced apex specialist superbadge.
- Modify OrderTrigger for handling only after Update
- Remove all the unnecessary code from the OrderTrigger and Call the AfterUpdate method in OrderHelper which takes Trigger.new and Trigger.old as input parameters
- Extract all Order Ids by iterating the Trigger.new list, whose old status (fetch status from Trigger.old list)is Constants.DRAFT_ORDER_STATUS and new status after update ( fetch status from Trigger.new ) is Constants. ACTIVATED_ORDER_STATUS. Invoke RollUpOrderItems in OrderHelper by Passing filtered Ids.
In RollUpOrderItems method,- Declare a Map<Id,Product2> named product map
- Create a List named productIds to store the productIds which are included in the Orders (Order Ids passed as the method argument).
- Select Id, Quantity_Ordered__c from Product2 based on the productIds list filter. Pass the Id and Product2 object into the productMap declared earlier
- productMap = new Map<Id,Product2>([Select id,Quantity_Ordered__c from product2 where id in :productIds]);
Loop through a query that aggregates the OrderItems related to the Products in the productMap keyset- <AggregateResult[] groupedResult = [Select Product2Id,sum(Quantity) totalQuantity from OrderItem where product2Id in :productMap.keySet() group by product2Id];
- for(AggregateResult result : groupedResult) {productMap.get((String)result.get(‘Product2Id’)).Quantity_Ordered__c= Integer.valueOf(result.get(‘totalQuantity’));}
Finally, update the productMap.values()Still, if you have any queries please let us know.
Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra