1

I'm trying to pass an object id to my component on my visualforce template but when it sends the mail it seems that it does not get the object id.

My Template:

<messaging:emailTemplate subject="RE: PAYMENT OF OUTSTANDING AMOUNT DUE AND OWING TO CQS TECHNOLOGY HOLDINGS PROPRIETARY LIMITED" recipientType="Contact" relatedToType="CreditAgreement__c">
<messaging:htmlEmailBody >
    <c:LetterOfDemandEmailComponent recordId="{!relatedTo.id}"/>
</messaging:htmlEmailBody>

My component:

<apex:component controller="LODEmailController" access="global" allowDML="true">
<apex:attribute name="recordId" description="Record Id" type="id" assignTo="{!record_Id}"/> 
<html>
    <head>
        <style  type="text/css">
            ol { counter-reset: item }
            li { display: block }
            li:before { 
                content: counters(item, ".") ". "; 
                counter-increment: item 
            }
            ul {
                list-style-type: none;
                padding: 0px;
                margin: 0px;
            }
            body {
                font-family:Arial, Helvetica, Verdana, Geneva, sans-serif;
                font-size:11px;
            }
            @page {
                @top-center {
                    content: element(header);
                }
                @bottom-left {
                    content: element(footer);
                }
            }
            div.header {
                padding: 5px;
                position: running(header);
            }
            div.footer {
                display: block;
                padding: 5px;
                position: running(footer);
            }
        </style>
    </head>
    <body style = "font-family:Arial, Helvetica, Verdana, Geneva, sans-serif; font-size:11px;">
        <div class="header" style="padding: 5px; position: running(header)">
            <apex:image url="{!$Resource.cqslogo_line_Underneath}" style="float: right;"/>
        </div>

        <div class="content">
            <br/>
            <br/>
            <p>{!creditAgreement.Account__r.Name}<br/>
            {!creditAgreement.Account__r.Billingstreet}<br/>
            {!creditAgreement.Account__r.BillingCity}<br/>
            {!creditAgreement.Account__r.Billingstate}<br/>
            {!creditAgreement.Account__r.BillingPostalCode}<br/>
            {!creditAgreement.Account__r.BillingCountry}<br/></p>



            <p>Date: <apex:outputText value="{0, date, dd' 'MMMM' 'yyyy}"><apex:param value="{!dateSent}" /></apex:outputText><br/><br/>

            Dear {!contactName}<br/><br/><br/>

            <b>RE: PAYMENT OF OUTSTANDING AMOUNT DUE AND OWING TO CQS TECHNOLOGY HOLDINGS PROPRIETARY LIMITED</b><br/></p><br/>

            <ol style = "counter-reset: item">
                <li style = "display: block">
                    On or about <apex:outputText value="{0, date, dd' 'MMMM' 'yyyy}"><apex:param value="{!dateCreated}" /></apex:outputText>, CQS Technology Holdings Proprietary Limited concluded a credit agreement number <b>{!creditAgreement.Name}</b>, with <b>{!creditAgreement.Account__r.Name}</b>. In terms of the agreement, it was agreed that CQS Technology Holdings Proprietary Limited would provide software for which <b>{!creditAgreement.Account__r.Name}</b> would be invoiced.
                    <table>
                        <tr>
                            <td><br/></td>
                        </tr>
                    </table>
                </li>
                <li style = "display: block">
                        The material express terms of the agreement determined, inter alia, that:<br/>
                        <ol style = "counter-reset: item">
                            <li style = "display: block">
                                <b>{!creditAgreement.Account__r.Name}</b> would be invoiced for the services rendered;
                            </li>
                            <li style = "display: block">
                                Payment of such invoices would be due and owing from the date of invoice; and
                            </li>
                            <li style = "display: block">
                                Should payment of such invoices remain outstanding of which the terms are: 
                                <ol>
                                    <li style = "display: block">
                                        100% of Software, and 50% of the consulting fee is due and payable upon invoice, if such terms are exceeded CQS Technology Holdings Proprietary Limited, will proceed with legal action as stated below.
                                    </li> 
                                </ol>
                            </li>
                        </ol><br/>
                </li>
                <li style = "display: block">
                    CQS Technology Holdings Proprietary Limited has duly complied with all its obligations in terms of the agreement.
                    <table>
                        <tr>
                            <td><br/></td>
                        </tr>
                    </table>
                </li>
                <li style = "display: block">
                    As per the credit agreement number <b>{!creditAgreement.Name}</b>, on or about <apex:outputText value="{0, date, dd' 'MMMM' 'yyyy}"><apex:param value="{!dateCreated}" /></apex:outputText>, CQS Technology Holdings Proprietary Limited duly issued its invoice/s to <b>{!creditAgreement.Account__r.Name}</b> for the services rendered, and Software provided, in the sum of R<apex:outputText value="{0, number, #,##0.00}"> <apex:param value="{!creditAgreement.Amount_Incl_VAT__c}"/> </apex:outputText> ({!Balance}). As at the <apex:outputText value="{0, date, dd' 'MMMM' 'yyyy}"><apex:param value="{!dateSent}" /></apex:outputText> an outstanding amount of R<apex:outputText value="{0, number, #,##0.00}"><apex:param value="{!creditAgreement.Current_Balance__c}"/></apex:outputText> ({!CurrentlyDue}) is due and payable immediately. A copy of the aforementioned invoice/s is/are annexed hereto.
                    <table>
                        <tr>
                            <td><br/></td>
                        </tr>
                    </table>
                </li>
                <li style = "display: block">
                    Notwithstanding the above, and in breach of your obligations, you have failed and/or refused to make payment of the amount outstanding, timeously or at all.
                    <table>
                        <tr>
                            <td><br/></td>
                        </tr>
                    </table>
                </li>
                <li style = "display: block">
                    In the circumstances, CQS Technology Holdings Proprietary Limited demands that <b>{!creditAgreement.Account__r.Name}</b> make payment of the amount outstanding on or before close of business within thirty (30) days of delivery hereof.
                    <table>
                        <tr>
                            <td><br/></td>
                        </tr>
                    </table>
                </li>
                <li style = "display: block">
                    Kindly ensure that payment of the aforementioned sum is made in full, in cash or by way of electronic transfer, into our banking account, the details of which are set out hereunder:<br/>
                    <ol style = "counter-reset: item">
                        <li style = "display: block">
                            <table style = "margin-Top: -16px; margin-left: 20px; font-family:Arial, Helvetica, Verdana, Geneva, sans-serif; font-size:11px;">
                                <tr>
                                    <td>Account Holder:</td>
                                    <td><b>CQS Technology Holdings Proprietary Limited</b></td>
                                </tr>
                                <tr>
                                    <td>Bank:</td>
                                    <td><b>Standard Bank</b></td>
                                </tr>
                                <tr>
                                    <td>Branch:</td>
                                    <td><b>Branch Code: 004305</b></td>
                                </tr>
                                <tr>
                                    <td>Account Number:</td>
                                    <td><b>001635522</b></td>
                                </tr>
                                <tr>
                                    <td>Ref:</td>
                                    <td><b>{!creditAgreement.Pastel_Account__r.Pastel_Account_Number__c}</b></td>
                                </tr>
                            </table>
                        </li>
                    </ol><br/>
                </li>
                <li style = "display: block">
                    Should you fail to make payment as aforesaid, we will immediately hand the matter over to our attorneys of record to institute legal proceedings against you without further notice or delay, and adversely list you with the relevant Credit Bureau.<br/>
                </li>
            </ol><br/>
            <p>
                Yours faithfully,<br/><br/>

                <apex:image url="{!$Resource.CraigLurieSignatureSmall}"/><br/>
                Craig Lurie<br/>
                CFO <br/>
                CQS Technology Holdings Proprietary Limited <br/>               
            </p>
        </div>

        <div class="footer" style = "display: block; padding: 5px; position: running(footer);">
            <apex:image url="{!$Resource.cqsfooter2}" />
        </div>          

    </body>
</html>

My Component Controller:

public class LODEmailController {
public CreditAgreement__c creditAgreement {get; set;} 
public id record_Id{get; set;}
public Date dateSent {get; set;} 
public Date dateCreated {get; set;} 
public String contactName {get;set;}
public String Balance {get;set;}
public String CurrentlyDue {get;set;}

public LODEmailController()
{
    dateSent = date.today();
    system.debug('record_id ' + record_Id);
    if(record_Id != null)
    {
        creditAgreement = 
        [
            SELECT
                Account__r.Name,
                Contact__r.Name,
                CreatedDate,
                Name,
                Outstanding_Balance__c,
                Amount_Incl_VAT__c,
                Account__r.AccountNumber,
                Account__r.Billingstreet,
                Account__r.BillingCity,
                Account__r.Billingstate,
                Account__r.BillingPostalCode,
                Account__r.BillingCountry,
                Pastel_Account__r.Pastel_Account_Number__c,
                Current_Balance__c
            FROM 
                CreditAgreement__c 
            WHERE 
                Id = :record_Id
        ];
        system.debug('creditAgreement ' + creditAgreement);
        creditAgreement.Account__r.Name = CapitalizeFirstLetter(creditAgreement.Account__r.Name);
        contactName = CapitalizeFirstLetter(creditAgreement.Contact__r.Name);
        dateCreated = date.newinstance(creditAgreement.CreatedDate.year(), creditAgreement.CreatedDate.month(), creditAgreement.CreatedDate.day());

        Balance = convertNumberToWord(creditAgreement.Amount_Incl_VAT__c);
        CurrentlyDue = convertNumberToWord(creditAgreement.Current_Balance__c);
    } 
    else 
    {
        creditAgreement = new creditAgreement__c();
        contactName = '';
        dateCreated = date.today();
        Balance = '';
        CurrentlyDue = '';
    }

}

And the code that send the email:

public void SendEmail(Id relatedTo, Id recipient, Id TemplateId, string email)
{
    try
    {
        Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
        emailMessage.setToAddresses(new String[] {email});
        emailMessage.setTemplateId(templateId);
        emailMessage.setTargetObjectId(recipient);
        emailMessage.setWhatId(relatedTo); 
        emailMessage.setSaveAsActivity(true);

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMessage });
    }
    catch(DMLException ex)
    {

    }
}

What am I missing? Why is the record Id Null?

3

The issue I see here is order of execution

The constructor runs first before your assignTO and hence you see the Id as NULL.I would move query inside your getter

private CreditAgreement__c creditAgreement;

public CreditAgreement__c getcreditAgreement(){
   dateSent = date.today();
   system.debug('record_id ' + record_Id);
   if(record_Id != null){
    creditAgreement = 
    [
        SELECT
            Account__r.Name,
            Contact__r.Name,
            CreatedDate,
            Name,
            Outstanding_Balance__c,
            Amount_Incl_VAT__c,
            Account__r.AccountNumber,
            Account__r.Billingstreet,
            Account__r.BillingCity,
            Account__r.Billingstate,
            Account__r.BillingPostalCode,
            Account__r.BillingCountry,
            Pastel_Account__r.Pastel_Account_Number__c,
            Current_Balance__c
        FROM 
            CreditAgreement__c 
        WHERE 
            Id = :record_Id
    ];
    system.debug('creditAgreement ' + creditAgreement);
    creditAgreement.Account__r.Name = CapitalizeFirstLetter(creditAgreement.Account__r.Name);
    contactName = CapitalizeFirstLetter(creditAgreement.Contact__r.Name);
    dateCreated = date.newinstance(creditAgreement.CreatedDate.year(), creditAgreement.CreatedDate.month(), creditAgreement.CreatedDate.day());

    Balance = convertNumberToWord(creditAgreement.Amount_Incl_VAT__c);
    CurrentlyDue = convertNumberToWord(creditAgreement.Current_Balance__c);
} 
  else{
    creditAgreement = new creditAgreement__c();
    contactName = '';
    dateCreated = date.today();
    Balance = '';
    CurrentlyDue = '';
   }

   return creditAgreement ;
}
0

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.