You need to sign in to do that
Don't have an account?
Laura StanleyHubbard
Email Last Case Comment - Help with Code
I'm trying to create a visualforce email template that I can attach in a workflow that goes out to certain users/account teams whenever a case comment is created/modified.
I can load the Apex Class but not the email template or component. I get the following error for component:
Error with email bc Ican't create component! Do I need to create a custom field for comments named last case comment?
I can load the Apex Class but not the email template or component. I get the following error for component:
Error with email bc Ican't create component! Do I need to create a custom field for comments named last case comment?
You need to change the component name as well as Its Value in componenet Refrence
Please find below updated code :
Component :
Please let me know, If it works don't forget to mark it as a best answer.
--
Regards,
Swayam
@Salesforceguy
Error: <messaging:emailTemplate> is required and must be the outermost tag in the markup at line 1 column 1
[User-added image]
Just Replace this line <c:SaaslastCaseComment caseId="{!relatedTo.Id}"/> with <c:SaaslastCaseComment lastCommentCaseId="{!relatedTo.Id}"/>
Let me know
Email template with error:
:
Apex Class Again
So frustrating. Appreciate the help! This is certainly not my space!
Just Update You Email Template Code with the following , You are refrering wrong Component name,
C: ----- is the name of your visualforce page component
<c:LastCommentComponent lastCommentCaseId="{!relatedTo.Id}" />
--
Regards,
Swayam
@salesforceguy
Email Template:
<messaging:emailTemplate recipientType="Contact"
relatedToType="Case"
subject="{!relatedTo.Subject}">
<messaging:htmlEmailBody >
<html><body>
Dear customer...
Description: {!relatedTo.Description}
Last comment: <c:LastCommentComponent lastCommentCaseId="{!relatedTo.Id}" />
</body></html>
</messaging:htmlEmailBody>
<messaging:plainTextEmailBody >
...
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Visualforce Component:
<apex:component controller="SaaSlastCaseComment" access="global">
<apex:attribute name="lastCommentCaseId" description="Salesforce Id of the Case" type="Id" assignTo="{!caseId}" />
<apex:outputtext value="{!lastCaseComment}" />
</apex:component>
Apex Class:
public class SaaSlastCaseComment {
public Id caseId {get; set;}
public String lastCaseComment {
get {
String lcc = [SELECT CommentBody FROM CaseComment WHERE ParentId = :caseId AND IsPublished = True ORDER BY LastModifiedDate DESC LIMIT 1].CommentBody;
return lcc;
}
set;
}
}
public class SaaSlastCaseComment {
public Id caseId {get; set;}
public String lastCaseComment {
get {
List<CaseComment> comments = [SELECT CommentBody FROM CaseComment WHERE ParentId = :caseId AND IsPublished = True ORDER BY LastModifiedDate DESC LIMIT 1];
String lcc = comments.size()>0 ? comments[0].CommentBody : null;
return lcc;
}
set;
}
}