您在此处:
创建 Apex 类
创建 Apex 类,以向请求保险证明的用户发送带有附件的电子邮件。
| 所需版本 |
| 适用于:Lightning Experience in Professional、Enterprise 和 Unlimited Edition, 其中 Financial Services Cloud 许可证通过 FSC Insurance 加载项启用。 |
| 所需用户权限 | |
| 要设置请求保险证明服务流程: | 行业服务流程、行业服务卓越性、Omnistudio、个案、服务目录请求对象读取、创建、编辑、删除、查看所有记录 和 FSC 保险 和 Financial Services Cloud 扩展或 FSC 销售 或者 Financial Services Cloud 基础 或者 Financial Services Cloud 标准 |
| 要使用请求保险证明服务流程: | 行业服务流程、行业服务卓越性、Omnistudio、个案、服务目录请求对象读取、创建、编辑、删除、查看所有记录 和 FSC 保险 和 Financial Services Cloud 扩展或 FSC 销售 或者 Financial Services Cloud 基础 或者 Financial Services Cloud 标准 |
- 单击设置,然后单击开发人员控制台。
-
创建 Apex 类。
示例:要向请求保险证明的用户发送带有附件的电子邮件,请使用以下脚本:
/************************* * @Class Name:- FSCInsServiceProcessSendEmail * @Description:- This apex class contains an invocable method used to send email along with attachment **************************/ global with sharing class FSCInsServiceProcessSendEmail { // Method to send email along with attachment and reurns either Success or Failure back to flow output variable @InvocableMethod(label='Send Email to user with attachment' description='Sends email to user from apex ') public static List<String> sendEmail(List<Requests> request) { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> response = new List<String>(); List<String> sendTo = new List<String> {request[0].sendToEmailId}; mail.setToAddresses(sendTo); mail.setSubject(request[0].emailSubject); mail.setHtmlBody(request[0].textTemplate); //Fetch attachment id associated to the caseId and append it to email as attachments List<Attachment> attList = new List<Attachment> ([SELECT Id, Name FROM Attachment WHERE parentId =: request[0].caseId WITH SECURITY_ENFORCED]); if (attList.size() > 0) { List<String> attachmentIds = new List<String> {attList[0].Id}; mail.setEntityAttachments(attachmentIds); } // Add email to the master list mails.add(mail); //Send all emails in the master list Messaging.SendEmailResult[] results = Messaging.sendEmail(mails); if (results[0].success) { response.add('Success'); } else { response.add('Failed to send email'); } return response; } //set of invocable variables which is used to set values from flow global class Requests { @InvocableVariable(label='Email Body' description='Text template of email body') global String textTemplate; @InvocableVariable(label='Send To Email Id' description='Email id of recipient') global String sendToEmailId; @InvocableVariable(label='CaseId' description='Case Id associated with attachment') global String caseId; @InvocableVariable(label='Email Subject' description='Email subject') global String emailSubject; } }
