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
gary_t_jmgary_t_jm 

Quote Line Item Sort Order

My users order quote line items on quotes using the sort button on the related list.

 

When I query the quote line items using Apex, I'm not sure what field to use in my order by clause to reproduce the order they specifies using the sort button on the related list. Is there a way to re-produce the user specified sort order in Apex code?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

SortOrder is in the system, despite not appearing in the Setup screen, or the Web Service's API Developer's Guide. It does appear in the WSDL under Develop > API, however. You can use it only if your API version is high enough (HINT: 16.0 is too low). Try changing your code's API to 23.0 or 24.0.

All Answers

sfdcfoxsfdcfox

Use the ORDER BY SortOrder ASC clause in your query. SortOrder is a (API) read-only field that defines the order of the line items.

gary_t_jmgary_t_jm

Thank you for your reply. I tried adding the order by in a test query but received the following error:

 

Compile error at line 1 column 31

No such column 'SortOrder' on entity 'QuoteLineItem'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

The test query I ran looks like this:

 

List<QuoteLineItem> qliList = [select Id from QuoteLineItem where QuoteId='0Q0Z0000000CgAy' order by SortOrder ASC];

 

When I look at the definition of the Quote Line Item object, I don't see the SortOrder field in the list of Standard Fields.

 

SFDC must somehow have this information though, because when I use the Sort button on the Quote Line Items related list, I'm able to rearrange the line order and the ordering I specify is persisted after I navigate away from the Quote page and then return.

 

Let me know if you have any thoughts about this, I'm considering opening a ticket with SFDC support.

 

sfdcfoxsfdcfox

SortOrder is in the system, despite not appearing in the Setup screen, or the Web Service's API Developer's Guide. It does appear in the WSDL under Develop > API, however. You can use it only if your API version is high enough (HINT: 16.0 is too low). Try changing your code's API to 23.0 or 24.0.

This was selected as the best answer
gary_t_jmgary_t_jm

This worked!

 

I was at version 20 with my Eclipse IDE.  After applying the update I'm now at version 24. I reran the query and it worked perfectly.

 

Thank you very much for your help!

Carl SilverCarl Silver

sfdcfox wrote:

Use the ORDER BY SortOrder ASC clause in your query. SortOrder is a (API) read-only field that defines the order of the line items.


Thank you, this worked perfectly :D

Kim GrondsmaKim Grondsma
Can you share the controller you created to fix this issue? I have spend days trying to sort the qoutelineitems in my visualforce page in the same order as on the qoute detail page. 
However I am not able to create a working controller for this