You need to sign in to do that
Don't have an account?
RichardR1
Please help with controller extension to achieve sorting
So I have a VF page to show an inline editable related list of another object. The problem is since I used apex:repeat, it sorts by createdDate instead of a certain field that I want it to sort, which is the standard Name field. I have just started self studying Apex development and no prior coding exp.
Below is the extension:
public class IVExtension { public Interview__c i { get; set; } public List<Interview_Questions__c> q=new List<Interview_Questions__c>([SELECT Parameter__c,id FROM Interview_Questions__c WHERE Interview_Questions__c.Interview__c =:i.id ORDER BY Parameter__c DESC ]); public ApexPages.StandardController sc; public IVExtension(ApexPages.StandardController sc) { i = (Interview__c)sc.getRecord(); q = [SELECT Parameter__c,id FROM Interview_Questions__c WHERE Interview_Questions__c.Interview__c =:i.id ORDER BY Parameter__c DESC ]; } public PageReference saveRecord() { update i.Interview_Questions__r; update i; return null; } }
Here is my VF page:
<apex:page standardController="Interview__c" sidebar="false" > <apex:form > <div align="center"> <apex:commandButton action="{!quicksave}" value="Save" /> </div> <apex:pageBlock mode="maindetail" > <apex:pageBlockSection columns="4"> <apex:pageBlockSectionItem dataStyle="width:25%;text-align:center;background-color:#0E2D46;color:white;padding:7px"> <apex:outputText > <b> Parameter </b></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width:10%;text-align:center;background-color:#0E2D46;color:white;padding:7px" > <apex:outputText > <b>Question</b> </apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width:35%;text-align:center;background-color:#0E2D46;color:white;padding:7px" > <apex:outputText > <b>ECA Rating</b> </apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="text-align:center;background-color:#0E2D46;color:white;padding:7px"> <apex:outputText > <b>Response / Notes</b> </apex:outputText> </apex:pageBlockSectionItem> <apex:repeat value="{!Interview__c.Interview_Questions__r}" var="ques" > <apex:pageBlockSectionItem dataStyle="width:10%;padding:7px;background-color:#0E2D46;color:white"> <apex:inputField value="{!ques.Parameter__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width:30%;padding:7px;background-color:#0E2D46;color:white"> <apex:outputField value="{!ques.Question__c}" style=""/></apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width:5%;padding:7px"> <apex:inputField value="{!ques.ECA_Rating__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width:55%;padding:7px"> <apex:inputField value="{!ques.Response_Notes__c}"/> </apex:pageBlockSectionItem> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> <div align="center"> <apex:commandButton action="{!quicksave}" value="Save" /> </div> </apex:form> </apex:page>
Thanks,
Richard
Changing the query to sort it by name should work.
Try:
public List<Interview_Questions__c> q=new List<Interview_Questions__c>([SELECT id,Name,Parameter__c FROM Interview_Questions__c WHERE Interview_Questions__c.Interview__c =:i.id ORDER BY Name ASC ]);
Thanks