You need to sign in to do that
Don't have an account?
Re-opening the disscussion of SortOrder on OpportunityLineItem
I'd like to re-open the discussion of SortOrder on the OpportunityLineItem object. A thread from 3.5 years ago can be located here:
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=3154
Looks like people from SF were going to look into it but obviously nothing has come to fruition. The reason I have put this in the Visualforce board is that we have have a few VF applications that could really take advantage of access to this field. Visualforce has also opened up new possibilities to UI design where the ability to manage SortOrder could be useful.
Also, no offense to salesforce.com, but the tool for sorting OpportunityLineItems is not that useful when there are multiple products with the same name. I have actually built a pretty slick sorting application but this is currently useless.
A lot of the concerns were about error handling. What happens if you have 3 line items but sort order is defined as, 1, 2, 2. Or 1, 2, 4. How about just throwing a sortOrder exception and force the developers to write good code?
Ideas? Thoughts?
http://ideas.salesforce.com/article/show/10092062/OpportunityLineItem_SortOrder_to_be_CreatableUpdatable
-Jason
Message Edited by TehNrd on 09-05-2008 01:22 PM
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=3154
Looks like people from SF were going to look into it but obviously nothing has come to fruition. The reason I have put this in the Visualforce board is that we have have a few VF applications that could really take advantage of access to this field. Visualforce has also opened up new possibilities to UI design where the ability to manage SortOrder could be useful.
Also, no offense to salesforce.com, but the tool for sorting OpportunityLineItems is not that useful when there are multiple products with the same name. I have actually built a pretty slick sorting application but this is currently useless.
A lot of the concerns were about error handling. What happens if you have 3 line items but sort order is defined as, 1, 2, 2. Or 1, 2, 4. How about just throwing a sortOrder exception and force the developers to write good code?
Ideas? Thoughts?
http://ideas.salesforce.com/article/show/10092062/OpportunityLineItem_SortOrder_to_be_CreatableUpdatable
-Jason
Message Edited by TehNrd on 09-05-2008 01:22 PM
I know this post is old, but it seems that a lot of people are interested in it. I needed this too so I came up with a hacky workaround that works for my needs. As you probably know, SFDC has a Sort button on the product related list where one can manually change the sorting of each individual product (you do not specify, for instance, sort by the product name). In the background, this interface is posting the results of the form to /oppitm/lineitemsort.jsp which results in the SortOrder field of the OLIs to be updated based on the users selection. Unfortunately, the SortOrder field is not writable via apex (things would be much easier if they were).
So, the first step is to have an apex web service that does the custom sorting logic and returns a comma separate list of OLI IDs in the desired sort order. Here is an example of my web service that sorts the OLIs for me based on my sorting requirements:
We are going to use the list of OLI Ids from the above web service in a JavaScript button that sits on the product related list. After reverse engineering how /oppitm/lineitemsort.jsp is called to commit the sort through SFDC's OOTB sort interface, I was able to come up with the correct button JavaScript to recreate a POST request to this JSP with the list of sorted OLI IDs from the web service:
So, after the user clicks the custom JavaScript sort button, the interaction with the sorting web service and /oppitm/lineitemsort.jsp results in the SortOrder field of the OLIs being set to the desired values and thus the OLIs are displayed in the desired sort order in the related product list.
All Answers
-Jason
I havent heard anything from salesforce. I just don't think there are enough people asking for it.
Here are two ideas but they aren't gaining much traction:
http://ideas.salesforce.com/article/show/10092062/OpportunityLineItem_SortOrder_to_be_CreatableUpdatable#skin=le
http://ideas.salesforce.com/article/show/10092189/Programmatically_change_order_of_Opportunity_Product_Line_Items#skin=le
I could make the lives our sales reps really happy with this feature. They waste so much time trying to sort line items.
Hi,
Although this is not exactly what you are looking for, it may help.
I have designed a Apex class that sorts by any field a list of any object (standard or custom) returned by a SOQL.
I put the class in a message called "A gift for you: Sorting any object (custom or standard) by any field" in the community boards.
This is the link:
http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=11655#M11655
Enjoy,
Andres Perez
Hi Andres, Are you sure that you can resort the Opportunity Product Items ? Because normally you can't ... µIt's done automatically by SortOrder and Product Name !
gonna have a look to you code later 'causer I'm quiet busy in this moment
Thanks a lot for your reply ...
Mig
Hi,
If you can bring the data with a SOQL statement, and you can display it in a datatable then the data has the structure required to be soreted by the class I have built.
Note that displaying the data in a datatable is not required for this sorter to work, what I meant is to be able to access each field from the list of sObjects returned by the SOQL.
The sorting class sorts the data that has been brought from the database using SOQL.
I'll tested agains the opportunity product items to see if it works and I'll let you know what I find.
Hi,
I have tried a SOQL like this:
SELECT LastModifiedDate, ListPrice, Opportunity.Name, SortOrder from OpportunityLineItem
and I was able to sort by everyfield. The SortOrder field had all null values, not sure if this is related with the problem you were reporting before.
But, anyways... Do you really want to sort by this field if you do not have control as to the values that go into this field?
This is exactly the issue. We want control of what values go into this field.
Hi,
Why no have a custom field where you do have control on the data that goes into the field?
I know this post is old, but it seems that a lot of people are interested in it. I needed this too so I came up with a hacky workaround that works for my needs. As you probably know, SFDC has a Sort button on the product related list where one can manually change the sorting of each individual product (you do not specify, for instance, sort by the product name). In the background, this interface is posting the results of the form to /oppitm/lineitemsort.jsp which results in the SortOrder field of the OLIs to be updated based on the users selection. Unfortunately, the SortOrder field is not writable via apex (things would be much easier if they were).
So, the first step is to have an apex web service that does the custom sorting logic and returns a comma separate list of OLI IDs in the desired sort order. Here is an example of my web service that sorts the OLIs for me based on my sorting requirements:
We are going to use the list of OLI Ids from the above web service in a JavaScript button that sits on the product related list. After reverse engineering how /oppitm/lineitemsort.jsp is called to commit the sort through SFDC's OOTB sort interface, I was able to come up with the correct button JavaScript to recreate a POST request to this JSP with the list of sorted OLI IDs from the web service:
So, after the user clicks the custom JavaScript sort button, the interaction with the sorting web service and /oppitm/lineitemsort.jsp results in the SortOrder field of the OLIs being set to the desired values and thus the OLIs are displayed in the desired sort order in the related product list.
Hi ,
I have tried your Code but its not getting saved Records.
can you please provide any suggestions.
Regards,
V'nath.
Can you describe your problem in more detail? I do not understand what you mean. FYI, this is still working for us today in Winter '12.
Hi,
i have used Samed Code in Different Sandboxes but its working in all sandboxes except one.
i got the Erro "Unable to Access Page" . Please help Regards this.
Advanec Thanks.
Hi,
i have used Samed Code in Different Sandboxes but its working in all sandboxes except one.
i got the Erro "Unable to Access Page" . Please help Regards this.
Advanec Thanks.
Thanks kpeters for posting this. It worked good in my managed package, but SF will not allow webservice call outs in Professional Edition org. I am thinking to call a VF page from a list button. This page will call a controller method that will return the comma seperated ids, which it does, but obiously I am doing something wrong here. Probably to do with my lack of understanding of DOM.
Please see below, I am just copying your solution in a JS in VF page, but I get an error. Any advise is appreciated.
Error message:
You are missing information needed by the page you have attempted to access. If you believe this is an error, please refresh your screen. If the error persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.
URL: https://na14.salesforce.com/oppitm/lineitemsort.jsp
Thanks for your time
kpeters, thanks for the great code. Any idea on how to call this JavaScript automatically on "after OLI insert"?
Any one figure out how to get around the "Unable to Access Page" error for this form post?
Does this workaround still work?
If I look at what sfdc is sending in the post of this page, it now also contains a _CONFIRMATIONTOKEN parameter.
If I try this, the page seems to open but it's not automatically submitting.
Any ideas?
Yes, everything still works fine. I've implemented this in our org, and it's working as usual.
Koene_V did you ever find a solution for this? I'm trying to implement this with apex and visualforce so users can customise the order instead of relying on ordering by queries but like a lot of other people I'm getting sent to the "Unable to access page" error. I notice the url is /oppitm/lineitemsort.jsp which suggests that I should be able to get past this somehow by stopping that page from having to load, anyone solved this issue?
So did you have to display the products in a custom related list in order to display them in your own order?
I think like someone mentioned earlier that there may be an issue with missing the _CONFIRMATIONTOKEN value. It appears to be dynamically generated and if you open the standard Sort page and change it (inspect it with Chrome and change the value) then the Save button doesn't work.
Without knowing how the key is generated I think we're screwed.
The Javascript workaround still works, but will only work as button on a standard object detail page/list, not a as script on a VF page.
Can you guide me how to create the web service in the first piece?
I tried to save it as a class but it wont let me save? is there anything i should add to the code?
Thanks
From VF page it is redirected to "lineitemsort.jsp" and then back to opporutnity with line items sorted. Any ideas on how they have done it?
// tests CustomSort
static testMethod void customsort_TestController() {
List < Account > lstAccount = new List < Account > ();
Account testAccount = new Account();
testAccount.Name = 'Test Account';
lstAccount.add(testAccount);
Account testAccount1 = new Account();
testAccount1.Name = 'Test Account1';
lstAccount.add(testAccount1);
insert lstAccount;
Opportunity testOpp = new Opportunity();
testOpp.Name = 'Test Opp';
testOpp.StageName = 'To Be Searched';
testOpp.CloseDate = System.now().date();
testOpp.AccountId = testAccount.Id;
testOpp.CurrencyIsoCode = 'USD';
insert testOpp;
testOpp = [select Id, Name from Opportunity where Id = : testOpp.Id];
OpportunityLineItem testSort = new OpportunityLineItem();
testSort.Description = 'Test oppline 1';
testSort.PRODUCTNICKNAME__c = 'Test Product 1';
testSort.UnitPrice = 1.0;
testSort.PriceBookEntryId = '01u80000004LDj9AAG';
testSort.OpportunityId = testOpp.id;
testSort.Quantity = 1.0;
insert testSort;
testSort = [Select oli.Id, oli.Line_Number__c,PRODUCTNICKNAME__c
From OpportunityLineItem oli
Where oli.OpportunityId = :testOpp.id
ORDER BY oli.Line_Number__c];
system.test.startTest();
CustomSort controller = new CustomSort();
PageReference pageRef = new PageReference('/'+testOpp.id);
system.test.setCurrentPage(pageRef);
ApexPages.CurrentPage().getparameters().put('oppid', testOpp.id);
pageRef.getParameters().put('oppid', testOpp.id);
CustomSort.MRsort(testOpp.id);
System.assert(testSort != null);
system.test.stopTest();
}
I am being redirected to lineitemsort.jsp with sorted lineitems but it does not close own its own and the user requires to click Save button.
Does it work complety for any one? Thank you.
Sort Quote Line Items and Create PDF Made Easy in Salesforce