2

SalesForce のメール送信機能を使用すると、ファイルを添付できます。この添付ファイルをセールスフォースで、メールの送信元のオブジェクトに保存する方法を探しています。

私はセールスフォースからのこの制限を知っています

「添付ファイルは、Salesforce から送信されたメールには保存されません。メールと共に保存するには、添付ファイルを後でメールに関連付けるか、メール-to-ケース、メール-to-Salesforce、オンデマンドメールを使用して Salesforce に送信する必要があります。 -to-ケース、またはSalesforce for Outlook."

回避策はありますか?

4

3 に答える 3

0

1 つのオプションとして、Apex コードを使用して Object の Attachment オブジェクトに同じものをアップロードし、電子メールを送信することができます。

    //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(); 
        }
    }
}

注意点:

  1. ToAddress を apex コードにハードコーディングしただけですが、VF ページに同じものを追加できます。実際、メールの送信と同じ UI エクスペリエンスを提供できます。
  2. 上記のコードを試したり実行したりしていません。アルゴ/フローについて理解するためのリファレンスとしてこれを参照してください。
于 2013-09-17T12:26:50.350 に答える
0

Salesforce For Outlook を調べましたか? これは、タスク、会議、イベント、ECT のために Salesforce と同期する Outlook のアドオンです。ボタンを 1 回クリックするだけで、メールと添付ファイルを Salesforce のアカウントに保存することもできます。私は 700 人以上のユーザーの唯一の管理者であり、フィールド全体がこれを使用し、気に入っています。

于 2017-03-08T14:53:22.790 に答える