1

An Email template containing a VF component is being launched by flow.

Email Template

<messaging:emailTemplate subject="Manifest - Maritime Carrier Notification" recipientType="Contact" relatedToType="Account">
    <messaging:htmlEmailBody>
        <html>
            <body>
                <c:ManifestCarrierEmailTmpl accountRecord="{!relatedTo}"/>
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

VF Component

<apex:component controller="ManifestCarrierEmailTmplController" access="global">

    <apex:attribute name="accountRecord" description="The account record of the carrier" type="Account"
                    assignTo="{!carrier}"/>

    <table style="table-layout: fixed; width: 100%; font-family: Arial, Helvetica, sans-serif;">
        <tr>
            <td></td>
            <td align="center">
                State of Blank<br/>
                DEPARTMENT OF BLANK <br/>
            </td>
            <td></td>
        </tr>
        <tr/>
        <tr>
            <td></td>
            <td align="center"><b style="font-size: 20pt;">E-MANIFEST NOTIFICATION <br/> </b></td>
            <td></td>
        </tr>
        <tr/>
        <tr>
            <td>
            </td>
            <td align="center" style="font-size: 20;">
                <!--<b>{!carrier.CarrierEmailParentManifest__r.RecordType.Name}</b>-->
                <b>{!carrierRecord.CarrierEmailParentManifest__c}</b>
            </td>
            <td></td>
        </tr>
        <tr/>
        <tr>
            <td>
                <b>DATE: {!TODAY()}</b>
            </td>
            <td>
                <b>Emanifest Name: {!carrier.CarrierEmailParentManifest__c}</b>
            </td>
        </tr>
        <tr/>
        <tr>
            <td>
                <b>TO: {!carrier.Name}</b>
            </td>
        </tr> 
        <tr/>
        <tr>
            <td>
                <b>FROM: </b>
            </td>
            <td>
                Plant Quarantine Branch
            </td>
        </tr>  
        <tr>
            <td>
                {!$User.FirstName} {!$User.LastName}
            </td>
        </tr>                
    </table>

    <!--On Hold-->
    <apex:outputText rendered="{!onHoldShipments.size > 0}">
        <table style="table-layout: fixed; width: 100%; font-family: Arial, Helvetica, sans-serif;">
            <tr>
                <td>
                    <b>Status:</b>
                </td>
                <td>
                </td>
                <td align="center" style="font-size: 30pt; color:red;">
                    <b>ON HOLD</b>
                </td>
                <td></td>
            </tr>
        </table>
        <table style="table-layout: fixed; width: 100%; font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;">
            <thead style="background-color: grey;">
                <tr>
                    <th style="padding: 5px; border: 1px solid #000;">Vessel/Voyage</th>
                    <th style="padding: 5px; border: 1px solid #000;">Arrival Date</th>
                    <th style="padding: 5px; border: 1px solid #000;">Container</th>
                    <th style="padding: 5px; border: 1px solid #000;">Importer</th>
                    <th style="padding: 5px; border: 1px solid #000;">Inspection Status</th>
                    <th style="padding: 5px; border: 1px solid #000;">Hold Location</th>
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!onHoldShipments}" var="onHoldShipment">
                    <tr>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.VoyageFlight__c}"/>
                        </td>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.DateOfArrival__c}"/>
                        </td>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.ContainerNo__c}"/>
                        </td>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.Importer__r.Name}"/>
                        </td>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.Status__c}"/>
                        </td>
                        <td style="padding: 5px; border: 1px solid #000;">
                            <apex:outputField value="{!onHoldShipment.HoldLocation__c}"/>
                        </td>
                    </tr>
                </apex:repeat>
            </tbody>
        </table>
    </apex:outputText>

    <br/>
    <br/>

    <!--Released-->
    <apex:outputText rendered="{!releasedShipments.size > 0}">
        <table style="table-layout: fixed; width: 100%; font-family: Arial, Helvetica, sans-serif;">
            <tr>
                <td>
                    <b>Status:</b>
                </td>
                <td>
                </td>
                <td align="center" style="font-size: 30pt; color: green">
                    <b>RELEASED</b>
                </td>
                <td></td>
            </tr>
        </table>
        <table style="background-color: grey; table-layout: fixed; width: 100%; font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;">
            <thead>
            <tr>
                <th style="padding: 5px; border: 1px solid #000;">Vessel/Voyage</th>
                <th style="padding: 5px; border: 1px solid #000;">Arrival Date</th>
                <th style="padding: 5px; border: 1px solid #000;">Container</th>
                <th style="padding: 5px; border: 1px solid #000;">Importer</th>
                <th style="padding: 5px; border: 1px solid #000;">Inspection Status</th>
                <th style="padding: 5px; border: 1px solid #000;">Hold Location</th>
            </tr>
            </thead>
            <tbody>
            <apex:repeat value="{!releasedShipments}" var="releasedShipment">
                <tr>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.VoyageFlight__c}"/>
                    </td>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.DateOfArrival__c}"/>
                    </td>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.ContainerNo__c}"/>
                    </td>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.Importer__r.Name}"/>
                    </td>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.Status__c}"/>
                    </td>
                    <td style="padding: 5px; border: 1px solid #000;">
                        <apex:outputField value="{!releasedShipment.HoldLocation__c}"/>
                    </td>
                </tr>
            </apex:repeat>
            </tbody>
        </table>
    </apex:outputText>

    <!--No Hold and No Released-->
    <apex:outputText rendered="{!(releasedShipments.size = 0 && onHoldShipments.size == 0)}">
        <tr>
            <td colspan="4" align="center" style="padding: 5px; border: 1px solid #000;">
                No Data
            </td>
        </tr>
    </apex:outputText>

    <p style="font-family: Arial, Helvetica, sans-serif;">
        If there are any questions, please call: <br/> <apex:outputField value="{!carrier.CarrierEmailParentManifest__c}"/> <br/>
        Processed By: {!$User.FirstName} {!$User.LastName} {!NOW()} <br/>
        Carrier Copy
    </p>

</apex:component>

Apex Controller

public class ManifestCarrierEmailTmplController {

    Set<String> allowedStatus = new Set<String>{
        'Hold',
        'QA',
        'Partial Hold',
        'Released'
    };

    Set<String> holdLocations = new Set<String>{
        'Air Cargo Facility',
        'Sea Port'
    };

    public Account carrier {
        set;
        get;
    }
    
    public Account getCarrierRecord() {
        return [SELECT Id, 
            Name,
            CarrierEmailParentManifest__r.RecordType.Name, 
            CarrierEmailParentManifest__c,
            CarrierEmailParentManifest__r.Name,
            CarrierEmailParentManifest__r.PortContactPhone__c
        FROM Account WHERE Id =: carrier.Id][0];
    }
    
    public List<Shipment__c> getReleasedShipments() {
        Account acc = [
            SELECT CarrierEmailParentManifest__c
            FROM Account
            WHERE Id = :carrier.Id
        ];

        return [SELECT
            Id,
            VoyageFlight__c,
            DateOfArrival__c,
            ContainerNo__c,
            Importer__r.Name,
            Status__c,
            HoldLocation__c
            FROM Shipment__c
            WHERE Manifest__c =: acc.CarrierEmailParentManifest__c
            AND Carrier__c =: carrier.Id
            AND Status__c IN: allowedStatus
            AND HoldLocation__c NOT IN: holdLocations
            ORDER BY VoyageFlight__c
        ];
    }

    public List<Shipment__c> getOnHoldShipments() {
        Account acc = [
            SELECT CarrierEmailParentManifest__c
            FROM Account
            WHERE Id = :carrier.Id
        ];

        return [SELECT 
            Id, 
            VoyageFlight__c, 
            DateOfArrival__c, 
            ContainerNo__c, 
            Importer__r.Name, 
            Status__c,
            HoldLocation__c
            FROM Shipment__c
            WHERE Manifest__c =: acc.CarrierEmailParentManifest__c
            AND Carrier__c =: carrier.Id
            AND Status__c IN: allowedStatus
            AND HoldLocation__c IN: holdLocations
            ORDER BY VoyageFlight__c
        ];
     }

}

I'm calling the carrierRecord getter in the VF component but the error says that its missing a requested field "CarrierEmailParentManifest__c", etc when in fact, its part of the soql query. Can somebody point out what i'm missing ?

1 Answer 1

0

In your component I see this line

<b>Emanifest Name: {!carrier.CarrierEmailParentManifest__c}</b>

But in your controller I only see the normal {get; set;} for the property {!carrier}. But nowhere I see value being assigned to that property in controller. I think your query is to set the carrierRecord property not for carrier property thats what I think the issue is.

2
  • do you think if i make this class as an extension class and use a standard Account controller, i would no longer need to do those queries on fields and lookup fields ? Commented Jul 28, 2020 at 3:22
  • i get it now. thank you Commented Jul 28, 2020 at 7:46

You must log in to answer this question.

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