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
juacojuaco 

VisualforceArrayList size or length

Hi:

 

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">
  <tr>
   <td>{!line.PricebookEntry.ProductCode}</td>
   <td>{!line.PricebookEntry.Name}</td>
   <td>{!line.Quantity}</td>
   <td><apex:OutputField value="{!line.UnitPrice}"/></td>
   <td><apex:OutputField value="{!line.TotalPrice}"/></td>
 </tr>
</apex:repeat>

 

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.

 

 

 

DCSDCS
There is a size() method that you could use
juacojuaco

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?

 

{!Opportunity.OpportunityLineItems.size()}

 

It doesn't work for me.

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

Regards,

Juaco

DCSDCS

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

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

juacojuaco
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





{!line.PricebookEntry.ProductCode}




Number of LineItems:{!Opportunity.OpportunityLineItems}





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

4293DFX
4293DFB
4294DFB
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
juacojuaco
#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>

thangasan@yahoothangasan@yahoo

Hai

 

  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.

 

Regards

Thanga

juacojuaco

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

Regards

Juaco

SoloSolo

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}"/>
</apex:repeat>

 

 

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">