0

We have Sort button in OpportunityLineItem. Using this, customer may able to sort the products in the order they want, but in Preview (Visualforce page preview) it's dispaying default order (Ascending by product name) not in the order customer sort. I used SortOrder in ORDER BY but still I am not getting the order correctly. Here is my query in controller.

Oli= [Select
         ID, OpportunityId, Description, Opportunity.Reactive_Sheet__c,
         Opportunity.Service_Sheet__c, Service_Sheet__r.name, Maintenance_Reactive_Sheet__r.name,
         Quantity, Product2.name, Maintenance_Reactive_Sheet__c, Service_Sheet__c, 
         Product2.Stock_Unit__c, UnitPrice, TotalPrice, Opportunity.VAT_Rate__c, 
         Service_Sheet__r.Visit__r.Asset__r.Name,
         Show_Description__c, Line_Item_Description__c, Product2.Extended_Sales_Description__c,
         Product2.Sales_Description__c
     From OpportunityLineitem 
     Where OpportunityId =:Delnoteid 
     Order By SortOrder];

Delnoteid = the current Opportunity Id.

I am using this controller in Visualforce component and surprisingly my Query runs twice .In first run Query returns default order (by product name).In second run query I have the correct order (in which the customer sort i.e the condition given in query works) but my page uses first time run query so it display default order instead of sort order.

  • 1
    Providing additional details would help. Do you have a Visualforce page that you're using to display the OpportunityLineItem records? If so, it would help if you were to edit your question to include the code for the Visualforce page as well. Also, where are you getting SortOrder from? If you want to allow people to sort by both ASC (ascending) and DESC (descending) orders, you'll probably need to move to dynamic SOQL. – Derek F May 15 '17 at 15:44
  • When you say "We have Sort button in OpportunityLineItem" do you mean you have the standard button on the layout or do you mean that you created a custom button? – dsharrison May 15 '17 at 16:29
0

(Amended my response to an actual answer, given that I am not allowed to ask questions yet).

Given your statement about 2 queries being run, I suspect you are not rerendering the apex fragment after requerying.

IF your requery is triggered from the UI, such as via a commandButton, you could do something like this:

Your page:

<apex:pageBlockTable id="line-items">
...
</apex:pageBlockTable>


<apex:commandButton ...... action="{!queryOpportunityLineItems}" rerender="line-items"/>

Your controller method:

public void queryOpportunityLineItems(){
    // your query logic here
}
  • 2
    This would be more appropriate as a comment on the question, rather than an answer (because it doesn't really answer the question), so I'll be flagging this. I think you need 50 reputation before you're allowed to comment on other people's questions and answers. One way to get up to that amount of repuation without asking/answering questions is to help by editing questions to improve formatting or correct spelling/grammar issues (which I think you can do right away). – Derek F May 15 '17 at 15:33
  • I have edited my questions see the updated question above. – Sankar Ganesh May 15 '17 at 15:46
  • edited to be a response @DerekF – sunnymatharuuk May 15 '17 at 16:46
  • @SankarGanesh did the above work? – sunnymatharuuk May 16 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.