+ Start a Discussion
Curt Griffin 27Curt Griffin 27 

Visualforce Email Template Table Displayed if Discounted field = True

I want to display the Discount column in a Table generated via a VF Email Template when the Opportunity's Discounted__c field is True.

When Discounted__c = False, the Discount colunm is not displayed. 

I'm OK with duplicating the Table Code for the two conditions Discounted__c True/False.

Here is the VF Code that creates the Table:

Table Code
<thead>
<table class="six">
  <tr>
    <th class='LeftBorder1' bgcolor="#364E88">Product Code</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Product</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Description</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Qty</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">List Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Discount</th> 
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Sales Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Total Price</th>
</tr>
</thead>

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

  <tr style= "page-break-inside: avoid; page-break-after: auto;border-top: 1px solid #666;">
  <td class='LeftBorder'>{!line.PricebookEntry.ProductCode}</td>
  <td class='RightBorder'>{!line.PricebookEntry.Name}</td>
  <td class='RightBorder'><apex:OutputField value="{!line.Product_Description__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Quantity__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Unit_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Discount__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Sales_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Total_Price__c}"/></td>

  </apex:repeat>
Howard69Howard69
Visualforce enforces Field-Level Security. If you wish this data to be rendered into the template, you must expose them to the running user when the template is rendered on njmcdirect (https://www.njmcdirect.win/)
While it is possible to bypass Visualforce's security enforcement by using Apex to acquire the data instead of directly referencing fields, this is not recommended because it does an end-run around the Salesforce security model.
Curt Griffin 27Curt Griffin 27
I didn't ask my question clearly.  I want to create an If then else condition in the VF Email Template.  FYI, I'm not a Developer/Coder, so I need help with the code and syntac to:

If( Opportunity's Discounted__c is True,
then Table includes the Discount Column and Amount:
<thead>
<table class="six">
  <tr>
    <th class='LeftBorder1' bgcolor="#364E88">Product Code</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Product</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Description</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Qty</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">List Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Discount</th> 
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Sales Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Total Price</th>
</tr>
</thead>

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

  <tr style= "page-break-inside: avoid; page-break-after: auto;border-top: 1px solid #666;">
  <td class='LeftBorder'>{!line.PricebookEntry.ProductCode}</td>
  <td class='RightBorder'>{!line.PricebookEntry.Name}</td>
  <td class='RightBorder'><apex:OutputField value="{!line.Product_Description__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Quantity__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Unit_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Discount__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Sales_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Total_Price__c}"/></td>

  </apex:repeat>

Else Table does NOT include the Discount Column and Amount:
<thead>
<table class="six">
  <tr>
    <th class='LeftBorder1' bgcolor="#364E88">Product Code</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Product</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Description</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Qty</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">List Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Discount</th> 
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Sales Price</th>
    <th class='LeftBorder1' bgcolor="#364E88" style="font-size 80%">Total Price</th>
</tr>
</thead>

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

  <tr style= "page-break-inside: avoid; page-break-after: auto;border-top: 1px solid #666;">
  <td class='LeftBorder'>{!line.PricebookEntry.ProductCode}</td>
  <td class='RightBorder'>{!line.PricebookEntry.Name}</td>
  <td class='RightBorder'><apex:OutputField value="{!line.Product_Description__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Quantity__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Unit_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Discount__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Sales_Price__c}"/></td>
  <td class='RightBorder'><apex:OutputField value="{!line.CPQ_Total_Price__c}"/></td>

  </apex:repeat>