Everything below are custom objects.
I selected the Opportunity Line Items in the order of Oli1, Oli2 and then Oli3.
Then I click on DMail button, and I see the table is populated in a different order than what I selected.
I was expecting the table to be populated with Oli1, Oli2 and then Oli3.
VF
<apex:page standardController="opportunity_line_item__c" recordSetVar="records" extensions="Dmail" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="Send Status Update">
<br/><br/><apex:inputTextarea value="{!emailBody}" Style="width:800px;" richText="true" required="false"/><br/>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex
public class Dmail
{
public ApexPages.StandardSetController standardController;
public String emailBody {get;set;}
public List<opportunity_line_item__c> l_opp {get;set;}
public opportunity_line_item__c opp {get;set;}
public Dmail(ApexPages.StandardSetController standardController)
{
this.standardController = standardController;
l_opp = new List<opportunity_line_item__c>();
for (opportunity_line_item__c sel : (List<opportunity_line_item__c>)standardController.getSelected())
{
opp = [select Name, opportunity__c, Quantity__c, Sales_Price__c, Id from opportunity_line_item__c where Id=:sel.Id];
l_opp.add(opp);
}
for (opportunity_line_item__c sel : l_opp)
{
emailBody = '<br/><br/><table border="1" style="border-collapse: collapse" cellspacing="20" cellpadding="20"><tr><th>Name</th><th>Quantity</th><th>Salesprice</th></tr>';
for (Integer j = 0; j<l_opp.size(); j++)
{
emailBody += '<tr><td>'+l_opp[j].Name+'</td><td>'+l_opp[j].Quantity__c+'</td><td>'+l_opp[j].Quantity__c+'</td></tr><br/>';
}
emailBody += '</table><br/>';
}
}
}
My main aim is to get the opportunity line items in the order which I selected in my VF page. What exact code changes can be done to achieve it.