0

I would like to check the size of the OpportunityLineItem related list in a Visualforce Email Template like below, where relatedTo is an Opportunity

<apex:outputPanel rendered="{!relatedTo.OpportunityLineItems.size != 0}">

But I get error:

Error: Invalid field 'size' for SObject 'OpportunityLineItem'.

What is the correct way to achieve this?

1
  • What is relatedTo here?
    – Raul
    Commented May 20, 2019 at 9:59

2 Answers 2

4

You won't be able to get the size directly in visualforce email template, for that you will have to use the repeat tag to get the count and then you can build further logic based on that variable.

<apex:variable var="sizeOfOpportunityLineItem" value="{!0}"/>
<apex:repeat value="{!relatedTo.OpportunityLineItems}">
    <apex:variable var="sizeOfOpportunityLineItem" value="{!sizeOfOpportunityLineItem + 1}"/>
</apex:repeat>
Number of Opportunity Line Items : {!sizeOfOpportunityLineItem}
4
  • This is not a Visualforce Page its an Visualforce Email Template I don't have a controller
    – Robs
    Commented May 20, 2019 at 10:15
  • Updated the answer, that should work for you. Commented May 20, 2019 at 10:25
  • Thanks Vijay. It works. But I will be honest, I am not keen on the solution, it seem unnecessarily convoluted.
    – Robs
    Commented May 20, 2019 at 10:35
  • Yup I can understand, but AFAIK there is no other way. @sfdcfox : Can you please see if this can be done in a better and simpler way. Commented May 20, 2019 at 10:46
0

Look like your OpportunityLineItems is an OpportunityLineItem instead of a List.

1
  • But I am using OpportunityLineItems not OpportunityLineItem
    – Robs
    Commented May 20, 2019 at 9:55

You must log in to answer this question.

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