+ Start a Discussion
Rory Figgins 18Rory Figgins 18 

Advanced Apex Superbadge Step 7

Sorry for the hijack, I can't create my own post.

Error: 
Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.

I am having an issue with validating the ext.getTotalPages method.
 
/**
     * @name GetTotalPages
     * @description
    **/
    public Integer getTotalPages(){
        return ((Decimal)this.standardSetController.getResultSize() / (Decimal)Constants.DEFAULT_ROWS).round(System.RoundingMode.CEILING).intValue();
    }

Here is my method toSetStandardSetController 
 
private void setStandardSetController() {
        if (this.selectedFamily != Constants.SELECT_ONE && this.selectedFamily != null) {
            this.standardSetController = new ApexPages.StandardSetController(Database.getQueryLocator([
                    SELECT
                            Id,
                            Product2.Name,
                            Product2.Family,
                            Product2Id,
                            UnitPrice,
                            Product2.Quantity_Remaining__c
                    FROM
                            PricebookEntry
                    WHERE Product2.IsActive = true
                    AND Product2.Family =: this.selectedFamily

            ]));
        } else {
            this.standardSetController = new ApexPages.StandardSetController(Database.getQueryLocator([
                    SELECT
                            Id,
                            Product2.Name,
                            Product2.Family,
                            Product2Id,
                            UnitPrice,
                            Product2.Quantity_Remaining__c
                    FROM
                            PricebookEntry
                    WHERE Product2.IsActive = true
            ]));
        }

        this.standardSetController.setPageSize(Constants.DEFAULT_ROWS);
    }

 
Best Answer chosen by Rory Figgins 18
Rocco SorrentinoRocco Sorrentino
I had 66 PricebookEntry in my organization. So 66/5 with round = 14. But the assertions was getTotalPages() = 3.

All Answers

Rory Figgins 18Rory Figgins 18
I can't at all see what is functionally wrong with what I am doing. Which is making everything so frustrating
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
I don't understand the question, where in the controller are you using the getTotalPages() method?
Rory Figgins 18Rory Figgins 18
My question is effectively just a second pair of eyes for someone who is familiar with pagination OR the Superbadge in question.

This method is referenced directly inside of the visualforce page, no referencing is required in the controller.

When Salesforce validates the Superbadge Challenge they run Apex assertions, calling the method directly. I am failing the challenge on the assetion of the getTotalPages() method. After spending an hour or so reviewing the code and fundamental functionality I can't see anything particularly wrong.
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
I'm starting step 7 of this superbadge just now....Ill let you know if I get stuck on this step as well or whether it works for me.
Rocco SorrentinoRocco Sorrentino
I'm getting the same error with getTotalPages()

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 I'm getting:
Challenge Not yet complete... here's what's wrong: 
Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.
 
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
When you get the log in the Developer Console, right click and click "View Raw Log". At the beginning of the log you can see the anonymous apex code that is asserting your code, etc. Does that give an indication of how salesforce is testing this? I've used this method in other challenges in this super badge to solve issues. 
Rocco SorrentinoRocco Sorrentino
Thank you Paul! It works. The problem was: Too many items in the PricebookEntry.
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
Great, can you clarify exactly what was wrong? Not sure why "Too many items in the PricebookEntry." would result in an error.
Rocco SorrentinoRocco Sorrentino
I had 66 PricebookEntry in my organization. So 66/5 with round = 14. But the assertions was getTotalPages() = 3.
This was selected as the best answer
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
Good to know!
Rocco SorrentinoRocco Sorrentino
I finally completed all challenges!
Rory Figgins 18Rory Figgins 18
Thanks guys!
Nick Tang 1Nick Tang 1
Dear Rocco 
Cloud you please sharing the code for me 
 
Nick Tang 1Nick Tang 1
hi @Rocco did you have the issue issue beforce 
I  do  not know  why it can been fix
please give me some advice 
 User-added image
Franck LewisFranck Lewis
For the error: Ensure that you implement all the pagination methods using the corresponding StandardSetController methods.
Got it fixed with 
selectedFamily = Constants.SELECT_ONE;

In OrderExtension constructor
praveen murugesanpraveen murugesan
Hello All,

Thanks @rocco. I have fixed it by having only 15 pricebookentires (remaining deleted).

Thanks,
Praveen Murugesan,