1

I have created a custom table in a visualforce page on quote. I use an apex repeat to render the amount of table rows for the quotelineitems.

Is it possible to show or hide my table header row based on if there are qouteline items without using a controller. I tried something like below but this doesnt work:

<td>
    <apex:outputText var="ql" value="{!Quote.QuoteLineItems}" rendered="{!ql.size != 0}">
        Title 
    </apex:outputText> 
</td>

UPDATE (how to achieve this with a condition on lineitem):

<apex:variable value="{!0}" var="count"/>
                     <apex:repeat rows="1" var="ql" value="{!Quote.QuoteLineItems}">
                         <apex:outputLabel value="{!IF(ql.Product2.Product_Type__c !='Yearly Subscription',' ',' ' )}" >
                         <apex:variable var="count" value="{!count+1}"/>
                         </apex:outputLabel>
                     </apex:repeat>
                     <apex:outputText rendered="{!count > 0}" >
                                    test
                      </apex:outputText>   
  • There's no way what you have above compiles as an apex:outputText does not have a "var" attribute. i think you meant to code an apex:repeat into your example and lost track part way through. You may want to update your example so that we understand what you are actually trying to do. – gNerb May 16 '18 at 15:02
  • @gNerb I updated my example – Thomas May 16 '18 at 16:19
  • apex variable is not supported in a repeat element as a counter: developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… see 2nd paragraph – gNerb May 16 '18 at 16:41
  • Find my updated answer with the use of Rollup Summary field – Santanu Boral May 16 '18 at 16:46
  • @Santanu The rollup cant be used in this case. I added my solution as an answer – Thomas May 17 '18 at 8:08
1

Create a rollup summary field COUNT_of_Line_Item__c on Quote object which returns the Count of Quote Line Items, which is easy to use in rendered attribute.

You can wrap entire table inside apex:outputPanel as follows

<apex:outputPanel rendered = "{!Quote.COUNT_of_Line_Item__c>0}">
<table/>
</apex:outputPanel>

or, you can use apex:variable

<apex:variable
    value="your value" var="var1"
    rendered="{!Quote.COUNT_of_Line_Item__c>0}">

</apex:variable> 

last one is preferable and works at my DE.

0

Salesforce does this in a roundabout way by default. If you were using a apex:pageBlock table, salesforce would have a rendered attribute on every column, something like (this can be observed by inspecting a related list on a record that has no related records):

<apex:pageBlockTable value="{!QuoteLineItems}" var="qli">
    <!-- The first two columns render if something exists -->
    <apex:column value="{!qli.field}" rendered="{!NOT(QuoteLineItems.empty)}"/>
    <apex:column value="{!qli.field2}" rendered="{!NOT(QuoteLineItems.empty)}"/>
    <!-- The following column renders if nothing exists -->
    <apex:column rendered="{!QuoteLineItems.empty}" headerValue="No records Available"/>
</apex:pageBlockTable>

Since you're using an apex:repeat to generate <tr> elements you could do something like:

<table>
    <thead>
        <apex:outputPanel layout='none' rendered='{!NOT(QuoteLineItems.empty)}'>
            <tr>
                <th></th>
            </tr>
        </apex:outputPanel>
        <apex:outputPanel layout='none' rendered='{!QuoteLineItems.empty}'>
            <tr>
                <th>No Records Available</th>
            </tr>
        </apex:outputPanel>
    </thead>
    <tbody>
        <apex:repeat rendered="{!NOT(QuoteLineItems.empty)}">
            <tr></tr>
        </apex:repeat>
    </tbody>
</table>

To achieve a similar result.

0

{!Quote.QuoteLineItems.size} would throw error

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

Here is my workaround to walk through list only once and get that whether list is empty or not by using apex:varibale and use that variable in your code.

<apex:page standardController="Quote">
                     <apex:variable value="{!0}" var="count"/>
                     <apex:repeat rows="1" var="ct" value="{!Quote.QuoteLineItems}">
                         <apex:variable var="count" value="{!count+1}"/>
                     </apex:repeat>
                     <apex:outputText rendered="{!count > 0}"  value="{!Quote.QuoteLineItems}" >
                                    test
                     </apex:outputText> 

</apex:page>
  • How would ik do this with a condition on a line item? See my update – Thomas May 16 '18 at 16:02
  • Ohh...I understand now...you want to increase the count conditionally....by using Product2.Product_Type__c from QuoteLine. Please note that Quote.QuoteLineItem only returns of Id of QuoteLine not it's fields....so you need to do query in apex controller – Ayub May 16 '18 at 17:54
0

My Findings - You cant use rollup summary with condition on cross related object with custom field - In this case I didnt need to write a contoller

Solution: - Create a checkbox on quote - Use processbuilder to check checkbox on quote from quotelineitems

In visualforce: Use render condition if checkbox checked

<apex:outputtext rendered="{!IF(Quote.Yearly_Subscription__c = true,true, false)}"> 
Hallo this is true (or your table)
</apex:outputText> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.