0

I am trying to get the last iteration record in apex:repeat tag and outputs the last iteration record using visualforce and not using apex. I tried using the first attribute but no luck. Please help me to get last recent record. Thanks in Advance!

  <apex:repeat value="{!relatedTo.Histories}" var="hist" first="">
            <apex:outputLabel value="Student Name: "/>
            <apex:outputText value="{!hist.NewValue}"/>
 </apex:repeat>

Student History

1 Answer 1

0

You can use apex:variable to calculate number of records to be skipped.

<!--Caluclate number of records to be skipped. -->

<apex:variable var="skip" value="{!-1}"/>
<apex:repeat value="{!relatedTo.Histories}" var="hist" >
    <apex:variable var="skip" value="{!skip + 1}"/>
</apex:repeat>

<!-- skip first relatedTo.Histories.length - 1 records -->
<apex:repeat value="{!relatedTo.Histories}" var="hist" first="{!skip}">
        <apex:outputLabel value="Student Name: "/>
        <apex:outputText value="{!hist.NewValue}"/>
</apex:repeat>
3
  • Hi @amitghadage, I tried executing but It skipped all the records. I am unable to output the last iteration record.
    – Sanjana
    Feb 26 at 13:10
  • @Sanjana What is the length of relatedTo.Histories & value of skip variable after iteration? Feb 26 at 18:37
  • When we update the Student Name in the UI, we get the old value and the New Value in the Histories. I want the recent changed record and skip the rest. Attached the Screenshot for reference.
    – Sanjana
    Feb 27 at 4:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .