• Daphne Calitz
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

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>
</messaging:emailTemplate>

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>
</apex:component>

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 sends 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?

Hi all,

I need to be able to display all my case comments and case emails in an <apex:repeat> block and they should be ordered by the date they were sent. I'm rather new to salesforce development and I'm not 100% sure how to do this. 

I have tried the following:

My Controller:

public class CaseFeedItem
    {
        public string creatorSmallPhotoUrl {get; set;}
        public string createdByName {get; set;}
        public string textBody {get; set;}
        public dateTime createdDate {get; set;}        
    }
    
    public list<CaseFeedItem> myCaseFeedItems {get; set;}

PageReference loadcase(Id caseID) 
    {
        system.debug('loadcase: starting... ');

        if (caseID == null)
            return page.conf_error;  /// NEED TO DO SOMETHING HERE
        
        mycase = 
            [
                SELECT
                        Id,
                        CaseNumber,
                        Subject,
                        Owner.Name,
                        CreatedDate,
                        Status,
                        Description,
                        Auditor_First_Name__c,
                        Auditor_Last_Name__c,
                        Auditor_Email__c,
                        Auditor_Phone__c,
                        Client_Name__c,
                        Client_Year_End_Date__c,
                        Client_No_of_Requests__c,
                        Client_Date_Requests_were_Sent__c,
                        Client_Audit_Deadline_Date__c,
                        ClosedDate,
                		IsClosed
                    FROM 
                        Case
                    WHERE
                        Id = :caseID
            ];
        
        system.debug('viewcase: case: '+mycase.subject);
        
        mycasecomments = 
            [
                SELECT 
                    Id,
                    CommentBody,
                    CreatorName,
                    CreatedById,
                    CreatedDate,
                    CreatorFullPhotoUrl,
                    CreatorSmallPhotoUrl,
                    IsPublished,
                    CreatedBy.Name
                    
                FROM 
                    CaseComment
                WHERE 
                    ParentID = :caseID
                ORDER BY
                    CreatedDate DESC
            ];
 
        myCaseEmails = 
        [
            SELECT
            	Id,
            	FromAddress,
            	FromName,
            	TextBody,
            	MessageDate,
            	ToAddress,
            	Subject
            	
            FROM
            	EmailMessage
            WHERE
            	ParentID = : caseId
            ORDER BY
            	MessageDate DESC
        ];
        newcomment = new CaseComment(ParentId=caseID);
        createCaseFeed();
        return null;

    }

 public void createCaseFeed()
    {
        for(CaseComment comment : mycasecomments)
        {
            CaseFeedItem feedItem = new CaseFeedItem();
            feedItem.creatorSmallPhotoUrl = comment.CreatorSmallPhotoUrl;
            feedItem.createdByName = comment.CreatedBy.Name;
            feedItem.textBody = comment.CommentBody;
            feedItem.createdDate = comment.CreatedDate;
            myCaseFeedItems.add(feedItem);
        }
        
        for(EmailMessage email : myCaseEmails)
        {
            CaseFeedItem feedItem = new CaseFeedItem();
            feedItem.creatorSmallPhotoUrl = null;
            feedItem.createdByName = email.FromName;
            feedItem.textBody = email.TextBody;
            feedItem.createdDate = email.MessageDate;
            myCaseFeedItems.add(feedItem);
        }
    }
And on my VF page:
 
<apex:repeat value="{!CaseFeedItems}" var="feedItem">
                        
      <div class="col-md-2 col-sm-2 xs-marginbottom">
            <img src="{!feedItem.creatorSmallPhotoUrl}" width="60" height="60" alt=""/><br/>
             <apex:outputText value="{!feedItem.createdByName}" />
       </div>
       <div class="col-md-10 col-sm-10">
              <apex:outputText value="{!feedItem.textBody}" />
               <br/><br/>
               <small>Date/Time Sent:&nbsp; 
                  <apex:outputText value="{0,date,MM'/'dd'/'yyyy  HH:MM}">
                        <apex:param value="{!feedItem.createdDate}" /> 
                  </apex:outputText>
               </small> 
       </div>
       <div class="col-md-12 col-sm-12">
           <hr/>
        </div>
</apex:repeat>


At the moment I get:

Error: Error occurred while loading a Visualforce page. on /confirmation/conf_caseView
Attempt to de-reference a null object 

And I would also like to find out how I would sort the "myCaseFeedItems" list by date

Hi all,

I need to be able to display all my case comments and case emails in an <apex:repeat> block and they should be ordered by the date they were sent. I'm rather new to salesforce development and I'm not 100% sure how to do this. 

I have tried the following:

My Controller:

public class CaseFeedItem
    {
        public string creatorSmallPhotoUrl {get; set;}
        public string createdByName {get; set;}
        public string textBody {get; set;}
        public dateTime createdDate {get; set;}        
    }
    
    public list<CaseFeedItem> myCaseFeedItems {get; set;}

PageReference loadcase(Id caseID) 
    {
        system.debug('loadcase: starting... ');

        if (caseID == null)
            return page.conf_error;  /// NEED TO DO SOMETHING HERE
        
        mycase = 
            [
                SELECT
                        Id,
                        CaseNumber,
                        Subject,
                        Owner.Name,
                        CreatedDate,
                        Status,
                        Description,
                        Auditor_First_Name__c,
                        Auditor_Last_Name__c,
                        Auditor_Email__c,
                        Auditor_Phone__c,
                        Client_Name__c,
                        Client_Year_End_Date__c,
                        Client_No_of_Requests__c,
                        Client_Date_Requests_were_Sent__c,
                        Client_Audit_Deadline_Date__c,
                        ClosedDate,
                		IsClosed
                    FROM 
                        Case
                    WHERE
                        Id = :caseID
            ];
        
        system.debug('viewcase: case: '+mycase.subject);
        
        mycasecomments = 
            [
                SELECT 
                    Id,
                    CommentBody,
                    CreatorName,
                    CreatedById,
                    CreatedDate,
                    CreatorFullPhotoUrl,
                    CreatorSmallPhotoUrl,
                    IsPublished,
                    CreatedBy.Name
                    
                FROM 
                    CaseComment
                WHERE 
                    ParentID = :caseID
                ORDER BY
                    CreatedDate DESC
            ];
 
        myCaseEmails = 
        [
            SELECT
            	Id,
            	FromAddress,
            	FromName,
            	TextBody,
            	MessageDate,
            	ToAddress,
            	Subject
            	
            FROM
            	EmailMessage
            WHERE
            	ParentID = : caseId
            ORDER BY
            	MessageDate DESC
        ];
        newcomment = new CaseComment(ParentId=caseID);
        createCaseFeed();
        return null;

    }

 public void createCaseFeed()
    {
        for(CaseComment comment : mycasecomments)
        {
            CaseFeedItem feedItem = new CaseFeedItem();
            feedItem.creatorSmallPhotoUrl = comment.CreatorSmallPhotoUrl;
            feedItem.createdByName = comment.CreatedBy.Name;
            feedItem.textBody = comment.CommentBody;
            feedItem.createdDate = comment.CreatedDate;
            myCaseFeedItems.add(feedItem);
        }
        
        for(EmailMessage email : myCaseEmails)
        {
            CaseFeedItem feedItem = new CaseFeedItem();
            feedItem.creatorSmallPhotoUrl = null;
            feedItem.createdByName = email.FromName;
            feedItem.textBody = email.TextBody;
            feedItem.createdDate = email.MessageDate;
            myCaseFeedItems.add(feedItem);
        }
    }
And on my VF page:
 
<apex:repeat value="{!CaseFeedItems}" var="feedItem">
                        
      <div class="col-md-2 col-sm-2 xs-marginbottom">
            <img src="{!feedItem.creatorSmallPhotoUrl}" width="60" height="60" alt=""/><br/>
             <apex:outputText value="{!feedItem.createdByName}" />
       </div>
       <div class="col-md-10 col-sm-10">
              <apex:outputText value="{!feedItem.textBody}" />
               <br/><br/>
               <small>Date/Time Sent:&nbsp; 
                  <apex:outputText value="{0,date,MM'/'dd'/'yyyy  HH:MM}">
                        <apex:param value="{!feedItem.createdDate}" /> 
                  </apex:outputText>
               </small> 
       </div>
       <div class="col-md-12 col-sm-12">
           <hr/>
        </div>
</apex:repeat>


At the moment I get:

Error: Error occurred while loading a Visualforce page. on /confirmation/conf_caseView
Attempt to de-reference a null object 

And I would also like to find out how I would sort the "myCaseFeedItems" list by date