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" extensions="IVExtension" sidebar="false" >
   <apex:form >
      <div align="center"> <apex:commandButton action="{!saverecord}" 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 dataStyle="width:35%;text-align:center;background-color:#0E2D46;color:white;padding:7px" > <apex:outputText > <b>ECA Rating</b> </apex:outputText>
       <apex:pageBlockSectionItem dataStyle="text-align:center;background-color:#0E2D46;color:white;padding:7px">
            <apex:outputText > <b>Response / Notes</b> </apex:outputText>
                <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>
   <div align="center"> <apex:commandButton action="{!saverecord}" value="Save" /> </div>




I believe that if you use the standard controller you cannot sort the child records.

Try using the controller extension similar to that example except instead of Account, you are using it for Interview_Question__c as is done in your existing code

You would then use a SOQL query to query for the Interview_Questions__c you want to display in your VF page.

Define a List<Interview_Questions__c> :

public List<Interview_Questions__c> questions;

create a getter method to query the questions from your VF page:

public Interview_Question__c getInterviewQuestions(){
    questions = [SELECT Id, Parameter__c, Question__c, ..... FROM Interview_Question__c WHERE Interview__c =: i.id **Order By Name ASC**]

    return questions;

in your VF Page, change the apex:repeat value to reference interviewQuestions

<apex:repeat value="{!interviewQuestions}" var="ques"> ...

this should essentially call the getInterviewQuestions() method and query for the Interview_Questions__c ordered by Name. Then it will use the List that is returned to display the interview questions returned by our query.

Just make sure you include all the fields you reference in your visual force page in the SOQL query.

Hope that helps

  • Thanks @Z33dawg, I am trying to order the Interview_Questions__c by a formula field(Parameter__c). The purpose of the extension is to be able to save changes to Interview_Questions__c records when they are edited from the VF in the related object (but that's not the issue) and order the Interview_Questions__c records by Parameter__c. Hope you can help further. Thanks
    – Richard
    Mar 4 at 20:45
  • updated the answer. Hope that helps and you can figure it out. You need to query for the interview questions in the controller extension and then refer to that list in the apex:repeat
    – Z33dawg
    Mar 5 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.