SalesForce电子邮件附件

SalesForce电子邮件附件,salesforce,Salesforce,使用SalesForce的发送电子邮件功能,它允许文件附件。我正在寻找一种方法,将此附件存储在salesforce中,以发送电子邮件的对象 我从salesforce那里知道这个限制 “附件不存储在Salesforce发送的电子邮件中。若要与电子邮件一起保存,附件必须稍后与电子邮件关联,或使用电子邮件至案例、电子邮件至Salesforce、按需电子邮件至案例或Salesforce for Outlook发送给Salesforce。” 有什么解决办法吗?一种方法是使用Apex代码在对象的附件对象中上

使用SalesForce的发送电子邮件功能,它允许文件附件。我正在寻找一种方法,将此附件存储在salesforce中,以发送电子邮件的对象

我从salesforce那里知道这个限制

“附件不存储在Salesforce发送的电子邮件中。若要与电子邮件一起保存,附件必须稍后与电子邮件关联,或使用电子邮件至案例、电子邮件至Salesforce、按需电子邮件至案例或Salesforce for Outlook发送给Salesforce。”


有什么解决办法吗?

一种方法是使用Apex代码在对象的附件对象中上载相同的内容,然后发送电子邮件

    //Code for attaching a file from Local Machine
//VF Page

    <apex:page controller="AttachmentUploadController">
<apex:sectionHeader title="Visualforce Example" subtitle="Attachment Upload Example"/>
    <apex:form enctype="multipart/form-data">
        <apex:pageMessages />
        <apex:pageBlock title="Upload a Attachment">

      <apex:pageBlockSection showHeader="false" columns="2" id="block1">

        <apex:pageBlockSectionItem >
          <apex:outputLabel value="File" for="file"/>
          <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
        </apex:pageBlockSectionItem>

        <apex:pageBlockSectionItem >
            <apex:commandButton action="{!upload}" value="Upload and send an Email"/>
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>


    </apex:pageBlock>
  </apex:form>
</apex:page>



//Controller

    public with sharing class AttachmentUploadController 
{
    public Attachment attachment 
    {
        get
        {
            if (attachment == null)
            attachment = new Attachment();
            return attachment;
        }
        set;
    }

    public PageReference upload() 
    {
        String parentId = System.currentPagereference().getParameters().get('pid');

        attachment.OwnerId = UserInfo.getUserId();  
        attachment.ParentId = parentId;
        attachment.IsPrivate = true;
        try
        {
            insert attachment;

            //Start: Send Email with Attachment
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[]{<<email IDs>>};

            mail.setToAddresses(toAddresses);             

            //Set email file attachments
            List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();

            // Add to attachment file list
            Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
            efa.setFileName(attachment.Name);
            efa.setBody(attachment.Body);
            fileAttachments.add(efa);

            //create attachment for object
            Attachment att = new Attachment(name = attachment.name, body = attachment.body, parentid = Trigger.new[0].id);
            insertAttList.add(att);
            mail.setFileAttachments(fileAttachments);

            //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            //END : Send Email with Attachment

            PageReference page = new PageReference('/' + parentId);
            return page;
        } 
        catch (DMLException e) 
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,system.Label.Error_uploading_attachment));
            return null;
        }
        finally
        {
            attachment = new Attachment(); 
        }
    }
}
//用于从本地计算机附加文件的代码
//VF页面
//控制器
具有共享类AttachmentUploadController的公共
{
公共附件
{
得到
{
如果(附件==null)
附件=新附件();
返回附件;
}
设置
}
公共页面引用上载()
{
字符串parentId=System.currentPagereference().getParameters().get('pid');
attachment.OwnerId=UserInfo.getUserId();
attachment.ParentId=ParentId;
附件.IsPrivate=真;
尝试
{
插入附件;
//开始:发送带有附件的电子邮件
Messaging.SingleEmailMessage mail=新建消息。SingleEmailMessage();
String[]toAddresses=新字符串[]{};
mail.setToAddresss(ToAddresss);
//设置电子邮件文件附件
List fileAttachments=新列表();
//添加到附件文件列表
Messaging.Emailfileattachment efa=新建Messaging.Emailfileattachment();
efa.setFileName(附件.Name);
efa.主体(附件.主体);
文件附件。添加(efa);
//为对象创建附件
附件att=新附件(名称=Attachment.name,正文=Attachment.body,parentid=Trigger.new[0].id);
insertAttList.add(附件);
mail.setFileAttachments(fileAttachments);
//发送电子邮件
Messaging.sendmail(newmessaging.SingleEmailMessage[]{mail});
//结束:发送带有附件的电子邮件
PageReference page=新的PageReference('/'+parentId);
返回页面;
} 
捕获(DME)
{
addMessage(新的ApexPages.message(ApexPages.severity.ERROR,system.Label.ERROR\u上传附件));
返回null;
}
最后
{
附件=新附件();
}
}
}
注意事项:

  • 我只在apex代码中硬编码了地址,但您可以在VF页面中添加相同的内容。事实上,你可以给用户界面的经验一样,发送电子邮件
  • 我没有尝试或执行上述代码;请将此作为参考,了解算法/流程

  • 你有没有调查过Salesforce的Outlook?它是Outlook的附加组件,可与Salesforce同步处理任务、会议、事件等。它还允许您只需单击一次按钮,即可将电子邮件和附件保存到Salesforce中的帐户。我是超过700个用户的唯一管理员,整个领域都在使用它,并且非常喜欢它