function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt HewsonMatt Hewson 

When adding products to an Opportunity the list is not sorted alphabetically

When adding products to an Opportunity the list is not sorted alphabetically.  How can I update this list view to display all my product alphabetically rather than randomly as the appear below?

User-added image

This is my Apex code where it brings in the product list.

<apex:outputLabel value="Product Name" for="productName"/> <apex:selectList id="productName" value="{!PricebookEntrys}" size="1" required="true"> <apex:selectOptions value="{!items}"/> </apex:selectList>

Can anyone help sort the products alphabetically?

Thanks in advance for any assistance
Best Answer chosen by Matt Hewson
Shashikant SharmaShashikant Sharma
Hi Matt,

You have to sort it in your apex class where you are fetching it. 

Use Order By Name ASC in your SOQL query in Apex Class.


Thanks
Shashikant

All Answers

Shashikant SharmaShashikant Sharma
Hi Matt,

You have to sort it in your apex class where you are fetching it. 

Use Order By Name ASC in your SOQL query in Apex Class.


Thanks
Shashikant
This was selected as the best answer
Matt HewsonMatt Hewson
Thanks Shashikant,

There was a sort() function messing everything up so I ordered by name and removed the sort() function and everything is working as expected.