0

VF ページを作成するには、以下の要件があります – 「<strong>登録フォーム」には

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

これを解決するのを手伝ってもらえますか?

ありがとう

4

1 に答える 1