You need to sign in to do that
Don't have an account?

VISUALFORCE - Sort Opportunity line items as they are displayed
I have a visual force page that uses the apex:repeat to loop through the Opportunity line items. B
ut the order is not as it displayed in the Opportunity. I
can check the SortOrder value of the line item, but this value is updated only when the user clicks the "Sort" button.
Questions:
ut the order is not as it displayed in the Opportunity. I
can check the SortOrder value of the line item, but this value is updated only when the user clicks the "Sort" button.
Questions:
- Is there a way to get items as they are displayed in the opp?
- If not, can I trigger the SortOrder value to be updated without the sort button?
var ProductsArr = new Array();
<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="lineitem"> var product_row = {name:"{!lineitem.product2.name}", quantity:{!lineitem.quantity}, ID:{!lineitem.product2.Hasavshevet_product_ID__c},price:{!lineitem.UnitPrice}};
console.log("{!lineitem.SortOrder}"); ProductsArr.push(product_row);
</apex:repeat>

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="lineitem"> var product_row = {name:"{!lineitem.product2.name}", quantity:{!lineitem.quantity}, ID:{!lineitem.product2.Hasavshevet_product_ID__c},price:{!lineitem.UnitPrice}};
console.log("{!lineitem.SortOrder}"); ProductsArr.push(product_row);
</apex:repeat>
I've gone through your requirement and instead of doing this you can query the product of opportunity in sorted order in VF Controller and
use the instance in VF Page, see the code below:
Apex Code--->
List<OpportunityLineItem> allLineItems{get;set;}
List<OpportunityLineItem> allLineItems=new List<OpportunityLineItem>([select id,UnitPrice,Product2.Name,Quantity,Product2.Hasavshevet_product_ID__c
from OpportunityLineItem ORDER BY Product2.Name ASC]);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com