In vf page i have created look up field (look up to custom object "PO") and created a "Add" custom button. When the user click on the show button all the Serial record names are displayed in Page block table.I need to sort this record based on their names (Eg: 1001, 1002, 1003.......). In the code i have sort() but the records are not showing in order.
Apex :
set<id> MapOfwrapperPO2 = new set<Id>();
public PageReference addPO(){
showSection5=true;
List<Keycode__c> poLineItems = [Select Id,Name,PO__c,PO__r.Name,PO__r.Container_Number__c,PO__r.Event_Number__c,PO__r.Source_of_Supply__c,PO__r.Booking_Date_Time__c,PO__r.Order_Type__c,PO__r.Season_Code__c,PO__r.Number_Pallets_Cartons__c from Keycode__c where id IN: selectedPoId ORDER By Name DESC ];
for(Keycode__c poLineItem:poLineItems){
if(!MapOfwrapperPO2.contains(poLineItem.id)){
wrapperPO wsinglePO = new wrapperPO(nextIdent++);
wsinglePO.poLineItemId = poLineItem.Id;
wsinglePO.poLineItemName = poLineItem.Name;
wsinglePO.poID = poLineItem.PO__c;
wsinglePO.poName = poLineItem.PO__r.Name;
wsinglePO.poContainer=poLineItem.PO__r.Container_Number__c;
wsinglePO.poEventnumber =poLineItem.PO__r.Event_Number__c;
wsinglePO.poSourceSupply=poLineItem.PO__r.Source_of_Supply__c;
wsinglePO.poOtype=poLineItem.PO__r.Order_Type__c;
wsinglePO.poSeasonCode=poLineItem.PO__r.Season_Code__c;
wsinglePO.poNumberPallets=poLineItem.PO__r.Number_Pallets_Cartons__c;
MapOfwrapperPO2.add(poLineItem.Id);
wPO.add(wsinglePO);
}
}
return null;
}
Vf code:
<apex:pageBlockSection id="poLineItemdetails" rendered="{!showSection5}" >
<apex:pageBlockTable value="{!wPO}" var="poLine" id="newItems" >
<apex:column value="{!poLine.poName}" title="PO Number" headerValue="PO Number"/>
<apex:column value="{!poLine.poContainer}" title="Container Number" headerValue="Container Number" />
<apex:column value="{!poLine.poEventnumber}" title="Event Number" headerValue="Event Number" />
<apex:column value="{!poLine.poSourceSupply}" title="Source Supply" headerValue="Source Supply" />
<apex:column value="{!poLine.poOtype}" title="Order Type" headerValue="Order Type" />
<apex:column value="{!poLine.poSeasonCode}" title="Season Code" headerValue="Season Code" />
<apex:column value="{!poLine.poNumberPallets}" title="Number Pallets" headerValue="Number Pallets" />
<apex:column value="{!poLine.poLineItemName}" title="PO LineItem" headerValue="PO LineItem" />
<apex:column headerValue="Action">
<apex:commandButton value="Delete" action="{!delWrapper}" rerender="newItems">
<apex:param name="toDelIdent" value="{!poLine.ident}" assignTo="{!toDelIdent}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="Add PO" action="{!addPO}" reRender="block" />
Attribution to: Lavanya Sanathkumar
Possible Suggestion/Solution #1
Use please comparable interface in your wrapper class.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_list_sorting_sobject.htm
This should solve all your problems.
Attribution to: Artur Kępczyński
Possible Suggestion/Solution #2
SOQL is very good at sorting so that is the cleanest place to do it.
In your SOQL your have:
from Keycode__c ... ORDER BY Name DESC
Exactly which name you want to sort by isn't clear to me but essentially you can introduce any reachable field in the ORDER BY term and also sort by multiple fields if appropriate e.g.:
from Keycode__c ... ORDER BY PO__r.Name, Name DESC
Attribution to: Keith C
Possible Suggestion/Solution #3
check this http://blogforce9dev-developer-edition.ap1.force.com/PageblockTableEnhancerADVDemo Use the below link https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000MbZI
Install this application in your salesforce instance and follow the guidelines to use that component above your page block table and you can find it really helpful for sorting of any column in your table.
Attribution to: sunny
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30750