Hi below code shows all case related to account but i want to show only last 3 cases. how can i show these in visual force email template.


subject="Case report for Account: {!relatedTo.name}"

replyTo="[email protected]">




        <p>Dear {!recipient.name},</p>

        <table border="0" >


                <th>Case Number</th><th>Origin</th>

                <th>Creator Email</th><th>Status</th>


            <apex:repeat var="cx" value="{!relatedTo.Cases}">


                <td><a href =












Please help.

Regards Russell baker

  • One more comment the merge field Recipient.name doesn't work currently it is a known issue. Try putting the related user field.. Commented Nov 1, 2015 at 16:02

1 Answer 1


You can use attribute rows for this

apex:repeat rows=3

In case results are showing in reverse order you can use first attribute to skip and have only last 3

apex:repeat first=(list.size -3)

Update :::

Looks like its hard to get list.size in this context and even if we get ,salesforce may randomly place data into repeater .

Only way i could now think of is using custom components in Visualforce template so that User has access to a controller class and SOQL query to do ordering and limit . Below is the sample from the guide


  • 1
    In other cases probably (with a MAX(list.size - 3, 0)) but I haven't found a way to get relatedTo.Cases.size to compile. (Not sure that the related objects are automatically queried either.)
    – Keith C
    Commented Nov 1, 2015 at 15:59
  • 1
    Hi Mohith, kudos for you It's working Commented Nov 1, 2015 at 16:15
  • which one worked ? Commented Nov 1, 2015 at 16:17
  • 1
    apex:repeat rows="3" Commented Nov 2, 2015 at 6:33
  • Hi Mohit,I afraid to say this but Activities come in reverse order and apex:repeat first=(list.size -3) is showing error. Can you please help me out to pull Activities from last to second last. Commented Nov 3, 2015 at 12:21

You must log in to answer this question.

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