Memos About Salesforce

Salesforceにハマってたこと!

Salesforce apex:actionSupport Rerenderが効かない時の対処法

こんにちは、管理人の@Salesforce.Zです。

別の記事でapex:actionSupportを利用することで ルックアップ項目の動作によって、別の項目に値を表示させることを詳細しました。

今回、VF画面にinputfieldのrequired = trueを設定する場合に困ったことを詳細し、さらにその対象法も共有します。

読んだら得ること

★ apex:actionSupport Rerenderが効かない時の対処法

目次

required = trueの場合、apex:actionSupport Rerenderが効かない

VF画面で、標準編集ページを実装することで、必須項目をrequired = trueで設定しました。

そして、VFで開発するということは標準で対応できない部分があるから、それはルックアップ項目の動作によって

自動入力させることです。

ルックアップ項目の動作によって自動入力はapex:actionSupportで対応しましたが、必須項目をrequired = trueで設定したことで、「xxxを入力してください」エラーメッセージが裏で発生し、apex:actionSupportのRerenderが効かない、必須項目を全部入力してから、動作するが、こりゃ困る

改善前のVF画面

<apex:form id="form_id">
    <apex:pageBlockSection>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!$ObjectType.customObject__c.Fields.account__c.Label}" for="accid" />
                        <apex:inputField value="{!customObject__c.account__c}" id="accid" required="true">
                            <apex:actionSupport event="onfocus" action="{!selectKaijyo}" rerender="kaijoAddress" />
                        </apex:inputField>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="住所" for="kaijoAddress" />
                        <apex:outputText value="{!kaijyoAdd}" id="kaijoAddress" />
                    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:pageBlockSection>
</apex:form

改善後のVF画面

<apex:form id="form_id">
    <apex:pageBlockSection>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!$ObjectType.customObject__c.Fields.account__c.Label}" for="accid" />
                        <apex:actionRegion>
                        <apex:inputField value="{!customObject__c.account__c}" id="accid" required="true">
                            <apex:actionSupport event="onfocus" action="{!selectKaijyo}" rerender="kaijoAddress" />
                        </apex:inputField>
                        </apex:actionRegion>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="住所" for="kaijoAddress" />
                        <apex:outputText value="{!kaijyoAdd}" id="kaijoAddress" />
                    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:pageBlockSection>
</apex:form

改善後と改善前、の違い

apex:actionSupportの前後を<apex:actionRegion>タグで囲んで、対応した、これによって、解決しました。 でないと、サーバ側に送信し、、エラーメッセージが発生すると思います。

レファレンス

Render fields based on picklist value