我有以下创建 VF 页面的要求 - '<strong>Registration Form' 有
1.名称字段
2.附件区——我们可以在那里浏览和添加任何文档
预期的UI- UI
以下是我的 VF 代码-
<apex:page standardController="Account" extensions="InputFileControllerExtension">
<apex:messages />
<apex:form id="theForm">
<apex:pageBlock >
<apex:pageBlockSection columns="2" showHeader="true" title="Personal Details" >
<apex:inputField value="{!Account.Name}" />
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>
<apex:commandButton value="Upload and save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
以下是 APEX 类-
public class InputFileControllerExtension
{
private final Account acct;
public Attachment attachment {get;set;}
public PageReference save()
{
attachment.parentid = acct.id;
insert attachment;
return stdController.save();
}
public InputFileControllerExtension(ApexPages.StandardController stdController)
{
attachment = new Attachment();
this.acct = (Account)stdController.getRecord();
this.stdController = stdController;
}
ApexPages.StandardController stdController;
}
我得到的错误 -
插入失败。第 0 行的第一个异常;第一个错误:REQUIRED_FIELD_MISSING,缺少必填字段:[Parent]:[Parent] 错误出现在页面 file_upload_test 组件中的表达式“{!save}”中:Class.InputFileControllerExtension.save:第 8 行,第 1 列
你能帮我解决这个问题吗?
谢谢