function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

VisualforceArrayList size or length



I'm new to Visualforce and I'm trying to retrieve the size of a VisualforceArrayList.


I'm aware that I can use the <apex:repeat> component this way:


<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
   <td><apex:OutputField value="{!line.UnitPrice}"/></td>
   <td><apex:OutputField value="{!line.TotalPrice}"/></td>


But what if I just want to know the number of LineItems inside my Opportunity.OpportunityLineItems VisualforceArrayList?


Is there a way to achieve this?

Something like .size() for ArrayLists or .length for Arrays in Java?


The other problem I have is that I'm using a Professional Edition License and it seems that I'm not able to create a Visualforce Custom Controller so I need to do it from the actual visualforce page.


Help would be very appreciated.




There is a size() method that you could use

Thanks for your reply DCS but I just don't seem to get it right.

Do you mean I could use the size() method like this?




It doesn't work for me.

How am I supposed to use the size() method you talk about?




I guess you are using an array and if so in your visual force page, you can do

{!oBjectArray.size==0} or something similar

mmm It is actually the Opportunity object.
I'm generating a Quote document in Visualforce rendered as pdf and for design purposes I need to know how many OpportunityLineItems there are in the desired Opportunity. Is that possible via pure Visualforce code without having to create a Custom Controller?

This is a sample code


Number of LineItems:{!Opportunity.OpportunityLineItems}

And this is what I end up seeing on the page:

Number of LineItems:[00k8000000CIxkfAAD, 00k8000000CIxkgAAD, 00k8000000CIxkdAAD]

Instead of the Ids on the Number of LineItems row I would like to see a number.
Number of LineItems:3
#Sorry, the code didn't come out right here's the sample code again: 

<apex:page standardController="Opportunity" showHeader="false"> <table> <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line"> <tr> <td>{!line.PricebookEntry.ProductCode}</td> </tr> </apex:repeat> <tr> <td>Number of LineItems:{!Opportunity.OpportunityLineItems}</td> </tr> </table> </apex:page>




  You can try like this create one custom field in Opportunity that will be increment using formula field by adding new OpportunityLineItems, Finaly you can display that custom field in the screen.





Thank you Thanga, I believe that is the best option I have at the moment.




Hello, try extra cycle before table output to clarify the number of  objects inside .


Number of  objects will be in {!rowNum}


<apex:variable value="{!0}" var="rowNum"/>
    <apex:repeat var="count" value="{!Opportunity.OpportunityLineItems}">
    <apex:variable var="rowNum" value="{!rowNum+1}"/>



khillan bhardwajkhillan bhardwaj

Dear sir ,


  the following code show list of OpportunityLineItem . is there is any possible way to sort this list by date or name.means accending or Decending Order . 

i know we can do such thing by using controller but i want to do this without any controller means either we can use javascript code in vf page. if u have solution then plz let me know


<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">