vf page pop-up content introduced by page layout under salesforce zero basic learning classic updates this page layout

In the classic environment, sometimes we can introduce a vf page to enhance the standard page layout function where page layout can not be implemented. Sometimes we may require some modifications of the vf page to update the page layout or the new window s changes that pop up in the current vf page to refresh the whole P. Age layout, the project met this demand, because the front-end is not good, it took some time to solve him, mark later met the same scene, you can take it directly.

Next, our demo pops up a new window based on the vf page currently introduced. The window reassignment of the variables in the current page layout needs to refresh the page layout automatically to achieve the desired effect.

GoodsDemoPage.page: Used to display a button, click on this button to pop up a sub-page

 1 <apex:page standardController="Goods__c">
 2     <script type="text/javascript">
 3         function openChangeStatusWindow() {
 4             var directURL = '/apex/GoodsDemoDirectPage?id={!Goods__c.Id}';
 5             window.open(directURL,'newwindow','height=100,width=200,top=200, left=350,toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no');
 6         }
 7 
 8         function refreshPagelayout() {
 9             window.top.location.href = '/{!Goods__c.Id}';
10         }
11     </script>
12     <apex:form>
13         <input type="button" value="empty Status state" onclick="openChangeStatusWindow();" />
14     </apex:form>
15 </apex:page>

GoodsDemoDirectPage.page: Used to empty the status of Status in Goods and update the page layout at the parent level.

 1 <apex:page  showHeader="false">
 2     <script src="../../soap/ajax/42.0/connection.js" type="text/javascript"></script>
 3     <script type="text/javascript">
 4         sforce.connection.sessionId='{!GETSESSIONID()}';
 5         function changeGoodsStatus() {
 6             var goods = new sforce.SObject("Goods__c");
 7             goods.Id = '{!$CurrentPage.parameters.Id}';
 8             goods.Status__c = null;
 9             result = sforce.connection.update([goods]);
10             console.log('result' + result);
11             if(result[0].getBoolean('success')) {
12                 window.opener.refreshPagelayout();
13                 window.close();
14             } else {
15                 alert('error occured');
16             }
17         }
18     </script>
19     <apex:form>
20         <input type="button" value="empty" onclick="changeGoodsStatus();" />
21     </apex:form>
22 </apex:page>

Configure GoodsDemoPage to the page layout of Goods__c, the sObject. When you click the Clear Statues button, a page pops up. When you click the Clear button in the page, the pop-up page will close and the current page layout will refresh automatically.

There are two key points: window.top and window.opener. The two differences are as follows:

window.top is used to return to the top-level window, the browser's window. GoodsDemoPage is embedded in the page layout. For GoodsDemoPage, its window.top points to the corresponding window of the current page layout.

window.opener is used to return to the page that opened this page. For GoodsDemoDirectPage, it is opened by GoodsDemoPage, so for GoodsDemoDirectPage, its window. opener points to GoodsDemoPage. So for this demo, we only need to call the refreshPageLayout method of GoodsDemoPage through window. opener, and then use window.top to point to the current URL to refresh in the method.

Summary: The article mainly involves the knowledge of js, because my JS compares dishes, if there are errors or better ways to welcome to point out, there are welcome messages that do not understand.

Keywords: Python Javascript

Added by rgriffin3838 on Sun, 28 Jul 2019 05:43:41 +0300