+ Start a Discussion
highland23highland23 

Replicating Quotes line item sort functionality

Hi folks,

 

We're looking to build a simple proposal app that allows users to add line items from price books, and then sort them as they'd like them to appear within the proposal.  Currently, the Quotes object does exactly this process, and I'm wondering if there's a native Apex/VF function that would allow us to have the same "Sort" button to sort the related list (product line items) that the Quotes object has in our custom object's related list?

Thoughts on how to achieve this easily?

Cheers!

kamlesh_chauhankamlesh_chauhan

It looks like that you want to achieve sorting functionality in VF page. Here is the sample code available on salesforce which might be helpful to you.

 

http://wiki.developerforce.com/page/Sorting_Tables

 

Regards,

Kamlesh Chauhan, (Founder & CTO, LogicRain Technologies)

kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn

 

Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

highland23highland23

Thanks for that reference, that's useful.  Unfortunately, what I'm looking to achieve requires manual sorting.  In the Quotes object, SFDC achieves this by effectively taking the user to a new screen that allows them to see in a sortable list (with up/down, top/bottom arrows) of product line items.  The reference you provided effectively allows you to sort by clicking a table heading and having it sort ASC or DESC.

 

Cheers.

sfdcfoxsfdcfox

Our project does this on a number of objects that use price books and product line items, and it is achieved through custom code we wrote manually. It's not as hard as it would first appear, especially if you give it a bit of thought. Here's a rough outline:

 

<apex:page controller="sortController">
  <apex:form>
    <apex:selectList multiselect="false" size="10">
      <apex:selectOptions value="{!lineItems}" />
    </apex:selectList>
    <apex:commandButton action="{!moveTop}" value="Top" />
    <apex:commandButton action="{!moveUp}" value="Up" />
    <apex:commandButton action="{!moveDown}" value="Down" />
    <apex:commandButton action="{!moveBottom}" value="Bottom" />
    <apex:commandButton value="Save" action="{!save}" />
  </apex:form>
</apex:page>

From this basic framework (I've left out most of the formatting, etc), you then write a few lines of code for actually doing the moving and saving. Overall, this is about 50-100 lines of page code and 50-100 lines of controller code; I could write this myself in just a couple hours. I don't think it's terribly complex. Unfortunately, there isn't a standard interface for this, and furthermore, it won't work with Opportunity line items or Quote line items (the field they use, SortOrder, is read-only in the API for now).