2

I create a map in the apex controller to store whether or not a QuoteLineItem has related records:

qliHasQimus = new Map<Id, Boolean>();

for (QuoteLineItem qli : qlis) {
    if (qli.QuoteItemMaintenanceUplifts__r.IsEmpty()) {
        qliHasQimus.put(qli.Id, false);
    } else {
        qliHasQimus.put(qli.Id, true);
    }
}

When I use this map inside of an apex column I get no errors:

<apex:column breakBefore="true" colspan="{!$ObjectType.QuoteLineItem.FieldSets.Quote_Cloner_Quote_Line_Detail.size + 1}"
    styleClass="nestedTableCell">
    {!qliHasQimus[qli.Id]}
</apex:column>

When I try to use it in the rendered attribute for the same column, I get the following error:

Map key null not found in map Error is in expression '{!qliHasQimus[qli.Id]}' in component in page clonequote

Example:

<apex:column breakBefore="true" colspan="{!$ObjectType.QuoteLineItem.FieldSets.Quote_Cloner_Quote_Line_Detail.size + 1}"
                         styleClass="nestedTableCell" rendered="{!qliHasQimus[qli.Id]}"/>

I've attempted to resolve it using an apex:variable tag:

<apex:pageBlockTable value="{!qlis}" var="qli">
    <apex:variable value="{!qliHasQimus[qli.Id]}" var="hasQimus"/>

And this doesn't throw any errors; however, none of the columns are rendered even if they have related items.

Right now I'm using it to render sub components of the column but that create's an an empty column in the table. I need to be able to hide this column if it is empty (it's a nested table).

3

You don't need a map at all. Just reference the empty property as in Is it possible to test list size from a VisualForce page?

<apex:column ... rendered="{!NOT(qli.QuoteItemMaintenanceUplifts__r.empty)}" />

Also just a note, you can be less verbose if you do want to use a Map. Instead of:

for (QuoteLineItem qli : qlis) {
    if (qli.QuoteItemMaintenanceUplifts__r.IsEmpty()) {
        qliHasQimus.put(qli.Id, false);
    } else {
        qliHasQimus.put(qli.Id, true);
    }
}

Use:

for (QuoteLineItem qli : qlis) {
    qliHasQimus.put(qli.Id, qli.QuoteItemMaintenanceUplifts__r.IsEmpty());
}
  • I tried "IsEmpty" and it didn't work, I'm dumb :P – gNerb Apr 30 '18 at 16:42
  • 1
    Nah it's a little bit surprising that it's .empty rather than .isEmpty. The behavior isn't exactly what you'd expect, but it's definitely good to know. – Adrian Larson Apr 30 '18 at 16:43
  • 1
    Did you try .size? – Adrian Larson Apr 30 '18 at 16:44
  • I did, it throws an error saying that null is not valid for the > operator. But .empty does work, I was just dumb and forgot to not it. – gNerb Apr 30 '18 at 16:45
  • As for verbosity, I have a picky boss :P – gNerb Apr 30 '18 at 16:45

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.