Salesforce在自定义页面中上传附件,并将类型设置为Feed附件

时间:2014-06-04 17:58:12

标签: salesforce custom-controls

我有以下代码,我收到错误 错误

正文:缺少必填字段:[正文] 上传附件时出错

   { public with sharing class FileUploadCtrl {

  public Attachment attachment {
  get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
  set;
  }

  public PageReference upload() {

    Property__feed p = new Property__feed();

    attachment.OwnerId = UserInfo.getUserId();
    //attachment.ParentId = 'a01o0000000QkQf'; // the record the file is attached to
    attachment.IsPrivate = true;

    try {

      feedItem f = new feedItem();
      f.ParentId = 'a01o0000000QkQfAAK';
      ///f.RelatedRecordId = attachment.Id;
      insert f;
      insert attachment;
      attachment.ParentId = f.Id;
      update attachment;

    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    } finally {
      attachment = new Attachment(); 
    }

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
    return null;
  }
}
}

我希望将它作为feeditem附件,它是一个个人顶点上传器 基本上我想将其类型更改为Feed Attachments ..而不是Attachments 这是图片样本 enter image description here

1 个答案:

答案 0 :(得分:0)

您可以创建FeedItem并将内容字段链接到附件正文等。您正在寻找吗?

public void addFeedItemAttachment(){
attachment.parentId=accId;
insert attachment;

FeedItem FI = new FeedItem();
FI.ParentId = accId;
FI.Body = 'Attachment added';
FI.ContentData = attachment.body;
FI.ContentFileName = attachment.Name;
insert FI;}

谢谢, 卡皮尔