【发布时间】:2016-01-19 05:22:16
【问题描述】:
我创建了一个具有附件上传功能的 visualforce 页面。 附件在自定义对象发票下上传。
现在内部用户可以使用选项卡访问此页面,也可以在 Salesforce 网站上公开访问。
上传功能在 Salesforce 实例中完美运行,但在网站上上传附件时,附件变量未设置。
这里是sn-p:(不完整的代码)
<apex:outputPanel id="AddAttachmentinner">
<div class="slds-form-element">
<label class="slds-form-element__label">Select Relevant Attachment:</label>
<br/>
<apex:inputFile title="Choose File" value="{!filebody}" filename="{!filename}" />
<br/> Please select only pdf, xls, doc, jpg, tiff, png type of files
</div>
</apex:outputPanel>
public pagereference SubmitInvoice(){
public String filename {
get;
set;
}
public Blob filebody {
get;
set;
}
public Attachment attachment {
get;
set;
}
if (filebody != null && filename != null && filename != '') {
attachment.Name = filename;
attachment.Body = filebody;
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = newInvoice.Id; // the record the file is attached to
attachment.IsPrivate = false;
upsert attachment;
}
}
我错过了什么吗?
【问题讨论】:
-
您确定为您的对象设置了适当的权限吗?站点用户作为 OwnerId 是否有效?您确定您的 newInvoice 记录具有 Id 值吗?你检查过开发者控制台的日志吗?只是抛出我会检查的想法。如果您在
apex:page下方添加apex:pageMessages标签,您也可能会从服务器收到一些错误消息。 -
嘿@Peter 感谢您回来。可以肯定的是,我在控制器的附件变量中插入了一个虚拟文件名和 blob 并且它起作用了。它只是在使用 inputfile 标签时没有设置附件。我在这里错过了什么吗?
标签: salesforce