+ Start a Discussion
Rahul Agrawal 43Rahul Agrawal 43 

Advanced Apex Specialist Superbadge Step 7

Hi All,

While working on the Advanced Apex Specialist Superbadge Step 7 I am facing a weird issue.
User-added image

The OrderExtension class is alreeady containing a variable of StandardSetController and in the OrderEdit page orderItemList is getting iterated.
But Salesforce doesn't support standardsetcontroller for OrderItem.

Hence getting the error: List controllers are not supported for OrderItem

Could anyone please help me, how to solve this issue.

Thanks,
Best Answer chosen by Rahul Agrawal 43
Zachery EngmanZachery Engman
Hi Rahul,

I don't believe you need to edit the QueryOrderRecord method at all.  

In the constructor, I think that it wants is to query query all active products.  
if(standardSetController == null){
        	standardSetController = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Product2Id, Product2.Family, Product2.Name, Product2.Quantity_Remaining__c, UnitPrice FROM PricebookEntry ...]));
        	standardSetController.setPageSize(Constants.DEFAULT_ROWS);
        }


Regarding the specific error you are seeing, I think it is unrelated to the above and referring to all of those Next, Previous, First, Last, etc. methods that are in the class.  Verify you add code to each of those using the related standardSetController method, for example, the First method:

 public void First(){
        standardSetController.first();
        GetOrderItems();
    }

There are similar methods off standardSetController for each of those respective stub methods in there that you need to fill in.

All Answers

Rocco SorrentinoRocco Sorrentino
Hi Rahul, I'm getting another error:
Challenge Not yet complete... here's what's wrong:  Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.
https://developer.salesforce.com/forums?id=9060G0000005O6OQAU
 
ravi reddy 68ravi reddy 68
Hi All,
While working with step 2 , I am getting following error.
Challenge Not yet Complete....ensure that trigger call correct method .Can anybody help me find out issues with ordertrigger .
Thanks in advance

 
ravi reddy 68ravi reddy 68
Also, I have issues with OrderHelper. I was wondering if anybody could help me clear step 2 with Orderhelper and ordertrigger?
Zachery EngmanZachery Engman
To OP:  StandardSetController here should not go off OrderItem.  The key is that you need to list all the active products, so your standardSetController should query off PricebookEntry.
Rahul Agrawal 43Rahul Agrawal 43

Hi Zachery,

I changed the reference of StandardListController to PriceBookeEntry but now showing the error to: Challenge Not yet complete... here's what's wrong:  Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.

In the OrderQueryRecord method: I added a condition to fetch all active pricebookentries for the order item:

public static Order QueryOrderRecord(Id orderId){
            SELECT Id, AccountId, EffectiveDate, Name, Status, Pricebook2Id,
                (
                    SELECT Id, OrderId, Quantity, UnitPrice, PricebookEntryId, Product2Id,
                         Product2.Name, Product2.Family, Product2.Quantity_Remaining__c
                    FROM OrderItems where PricebookEntry.isActive = true
                )
            FROM Order WHERE Id = :orderId

Below I assigned StandardController to PriceBookeEntry
Constructor: 
public OrderExtension(ApexPages.StandardController standardController){
        orderRecord = (Order)standardController.getRecord();
        orderItemMap = new Map<id,OrderItem>();
        if ( orderRecord.Id != null ){
            orderRecord = queryOrderRecord(orderRecord.Id);
        }
        orderItemList = new List<OrderItem>();
        OrderItemList.addAll(orderRecord.OrderItems);
        set<Id> p2ids = new set<Id>();
        for(OrderItem oitem : OrderItemList){
            p2ids.add(oitem.PriceBookEntryId);
        }
        List<PriceBookEntry> p2List = new List<PriceBookEntry>();
        if(p2Ids.size()>0){
            p2List = [select id from PriceBookEntry where id IN: p2Ids];
        }
        standardSetController = new ApexPages.StandardSetController(p2List);
        standardSetController.setPageSize(Constants.DEFAULT_ROWS);
    }

Still not able to fix this issue.
 

Zachery EngmanZachery Engman
Hi Rahul,

I don't believe you need to edit the QueryOrderRecord method at all.  

In the constructor, I think that it wants is to query query all active products.  
if(standardSetController == null){
        	standardSetController = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Product2Id, Product2.Family, Product2.Name, Product2.Quantity_Remaining__c, UnitPrice FROM PricebookEntry ...]));
        	standardSetController.setPageSize(Constants.DEFAULT_ROWS);
        }


Regarding the specific error you are seeing, I think it is unrelated to the above and referring to all of those Next, Previous, First, Last, etc. methods that are in the class.  Verify you add code to each of those using the related standardSetController method, for example, the First method:

 public void First(){
        standardSetController.first();
        GetOrderItems();
    }

There are similar methods off standardSetController for each of those respective stub methods in there that you need to fill in.

This was selected as the best answer
Rocco SorrentinoRocco Sorrentino
Hi Raul,

I suggest to inspect the Log inside the Developer Console and right click and click "View Raw Log" to see the anonymous apex code that is asserting your code.
You'll be able to check the errors. For example:

from the developer console:
13:04:31:053 EXCEPTION_THROWN [4]|System.AssertException: Assertion Failed: ext.getTotalPages() did not return the expected result.

and on Trailhead:
Challenge Not yet complete... here's what's wrong: 
Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.
ravi reddy 68ravi reddy 68
Hi All, I am working on advanced apex specialist Challenge 2 .I got error message " Challenge Not yet complete... here's what's wrong: Ensure that you loop through a query that aggregates the OrderItems related to the Products in the ProductMap keyset. " Please share Orderhelper class to check where i am doing mistake.
Abhishek-tandonAbhishek-tandon
Hi Zachery/Rocco,

Could you share your order extension class, my pagination is not working fine, also in case of edit, do we need show existing product only?
Abhishek-tandonAbhishek-tandon
Hi Zachery,

Is GetOrderItems is a new method created by you and in this you are preparing list of order items based on pricebookentries in the current standardsetcontroller current records.
Wacław SmagaWacław Smaga
Hi guys

I'm getting: System.AssertException: Assertion Failed: ext.getHasNext() did not return the expected result.
When I check in the UI, it works fine, buttons are disabled in right momets.

My getHasNext() method:
public Boolean GetHasNext(){
     return standardSetController.getHasNext();
}
Any ideas?
AMIT SINGH 2375AMIT SINGH 2375
Hi All,

Anyone can post the Apex class code here?
ravi reddy 68ravi reddy 68
@Amit Singh I have the same issue with standardsetcontroller pagination methods. 
ravi reddy 68ravi reddy 68
@Amit singh and Abhishek-tandon
Make sure  you have less than 15 products in trailhead org and check .Delete products manually if you have more than 15.you can get getTotalpages()working by having lessthan 15 which you confirm it in raw logs.You will no longer get error message "Ensure that you implement all the pagination methods using the corresponding StandardSetController methods."
Nirmallya_GhoshNirmallya_Ghosh
I am getting "Challenge Not yet complete... here's what's wrong: 
Ensure that you implement all the pagination methods using the corresponding StandardSetController methods" please help
 
Mayur_112Mayur_112
@Nirmallya,
After clicking on check challenge, check your developer console debug logs, some assert condition must be failing if it is regarding gettotalpages()  then check the count of pricebookentry records ideally it should be 12 and the number of pages should be 12/5 = 3. Delete any extra records.
Brian KesslerBrian Kessler
Hi,
This is driving me crazy.

I have 12 records and can confirm I am returning three.
I can even "game" the Apex to ensure the method returns nothing but 3 no matter what.

But still I get:
14:51:37:073 FATAL_ERROR System.AssertException: Assertion Failed: ext.getTotalPages() did not return the expected result.

This is insanity.
Worse than insanity because no developer worth his salt would create a test which is dependent upon the stability of data in the system.
(Never mind all the tests of implementation details!)
This test is a piece of shit.

How can these people judge whether we are "advanced developers" when they aren't qualified to develop paper airplanes in a kindergarten?

Argh!
 
Brian KesslerBrian Kessler
finally solved the problem
I've solved my problem...

There were two of them, both because the people creating Trailheads never learned the first principles of writing tests and apparently have limited communication skills as neither of these problems were obvious from their error messages:

1. As mentioned above, they are testing DATA -- If you have extra products, you fail.

So I had to delete some nonsense I introduced while I was playing with the system and doing my own manual and exploratory testing.


2. They are testing IMPLEMENTATION DETAILS.  If you don't have exactly what they are looking for, you fail.

Ultimately my problem was with the GetTotalPages() method.
It did not work when it looked like this:
public Integer GetTotalPages(){
        return (Integer)Math.ceil(standardSetController.getResultSize() / (Decimal)Constants.DEFAULT_ROWS);
    }

But it finally worked when I made it dirty like this:
public Integer GetTotalPages(){
        Integer totalPages = (Integer)Math.ceil(standardSetController.getResultSize() / (Decimal)Constants.DEFAULT_ROWS);
        System.debug('############ totalPages: ' + totalPages);
        return totalPages;
    }






 
Emilien Guichard 40Emilien Guichard 40
Hi there,

I deleted all the extra products I created but I'm still facing this error :

Assertion Failed: ext.getHasNext() did not return the expected result.

Any piece of advice ?
Thanks a lot.
 
AYANAYAN
Hi All , 

I'm facing issue in Advance Apex step 7 code.

Issue: Challenge Not yet complete... here's what's wrong: 
Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.

can any body share all the code for step 7
Oleg PogrebnyakOleg Pogrebnyak
If solutions above didn't help for you (as for me), ensure that Product2 and PricebookEntry IsActive fields are true.
For example query:
SELECT Name, Product2.Family, Product2.Name, Product2Id, UnitPrice, Product2.Quantity_Remaining__c  FROM PricebookEntry WHERE IsActive = TRUE ORDER BY Name
should return 12 rows.