tyoshikawa1106のブログ

- Force.com Developer Blog -

SFDC:VFページからの標準ページ更新について

カスタムボタンクリック時にJavaScriptでVFページをポップアップで表示、処理完了後に呼び出し元の標準ページをリフレッシュこういったことを行いたいケースがたまにあると思います。Visulaforceはドメインが異なるためJavaScriptから標準ページを操作することはできないようになっています。

Visualforceページが異なるドメイン(visual.force.com)から提供される


実際にやろうとするとどうなるか確認してみました。

カスタムボタンの処理 (JavaScript)
var result = popUpWindow('/apex/OppPopupDemo', 300, 300, 700, 150); 

function popUpWindow(url, l, t, width, height) { 
  return window.open(url, "window", "screenX=" + l + "px; screenY=" + t + "px: left=" + l + "px; top=" + t + "px; width=" + width + "px; height=" + height +"px; resizable:no; status:yes;"); 
}
Poupページの処理
<apex:page showHeader="false">
    <apex:form id="form">
        <apex:pageBlock id="block">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Close" onClick="return popupClose();" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Label" />
                    <apex:outputText value="Hello Salesforce Developers!" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script type="text/javascript">
        function popupClose() {
            try {
                window.opener.location.reload();
                window.close();
            } catch(e) {
                alert(e);
            }
            return false;
        }
    </script>
</apex:page>


カスタムボタンからJSでVFページを表示することは可能です。
f:id:tyoshikawa1106:20160330115241p:plain


ですが『 window.opener.location.reload();』などでリフレッシュしようとすると・・・
f:id:tyoshikawa1106:20160330115339p:plain


このようにSecurityErrorとなってしまいます。

SecurityError: Blocked a frame with origin "<自分のSalesforceのドメイン>" from accessing a cross-origin frame.


Salesforceにはリモートサイトの設定が用意されています。通常VFページ内でGoogle APIなど外部サイトのAPIを利用する際に設定するものです。ここにVFページのドメインを設定したケースも確認してみます。
f:id:tyoshikawa1106:20160330115701p:plain


この設定を行ってもSecurityErrorとなりました。
f:id:tyoshikawa1106:20160330115954p:plain


Visualforceページから標準ページを操作できるか聞かれたらできないと回答して問題なさそうです。