function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YuvikaYuvika 

Visualforce Poup window and parent page refresh

Hi,

I need help with visual force pages.

I am opening a pop up window on click of a button on one of my custom visualforce page. One pop up window, I am creating a new object and saving it.

 

On save , I need to save and close the pop up window and rerender the parent page with new results from database.

It would be great if sample code can be provided.

 

 

Thanks

Yuvika 

Taiki YoshikawaTaiki Yoshikawa

Hi.

 

Parent Page

<apex:page controller="ParentRefreshDemoController" tabStyle="Account" id="page">
    <apex:form id="form">
        <apex:actionFunction name="functionGetAccounts" action="{!getAccounts}" reRender="form" />
        <apex:pageBlock >
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Create Account" onClick="return onPopupButton();" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1">
                <apex:pageBlockTable value="{!accounts}" var="item">
                    <apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}">
                        <apex:outputField value="{!item.Name}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script>
        function onPopupButton() {
            url = "{!$Page.PopupCreateAccountPage}";
            ret = PopUpDialog(url, 600, 350);
            functionGetAccounts();
            return false;
        }
        
        function PopUpDialog(url, width, height) {
            return window.showModalDialog(url, window, "dialogWidth:" + width + "px; dialogHeight:" + height +"px; resizable:no; status:yes;"); 
        }
    </script>
</apex:page>

 ParentPage Class

public with sharing class ParentRefreshDemoController {
    
    public List<Account> accounts {get; set;}
    
    public ParentRefreshDemoController() {
        this.accounts = new List<Account>();
    }
    
    public void getAccounts() {
        this.accounts = [SELECT Id, Name FROM Account ORDER BY Name ASC LIMIT 10];
    }
}

 

 PopupPage

<apex:page controller="PopupCreateAccountController" showHeader="false" sidebar="false" applyHtmlTag="false" id="page">
    <body class="lookupTab">
        <apex:sectionHeader title="Create Account" />
        <br/>
        <apex:form id="form">
            <apex:pageBlock >
                <apex:pageBlockButtons location="top">
                    <apex:commandButton value="New Account" action="{!createAccount}" onComplete="return closeDialog();" />
                </apex:pageBlockButtons>
                <apex:pageBlockSection columns="1">
                    <apex:outputText value="A" />
                    <apex:outputText value="B" />
                    <apex:outputText value="C" />
                    <apex:outputText value="D" />
                    <apex:outputText value="E" />
                    <apex:outputText value="F" />
                    <apex:outputText value="G" />
                    <apex:outputText value="H" />
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </body>
    <script>
        function closeDialog() {
            window.close();
            return false;
        }
    </script>
</apex:page>

 PopupPage Class

public with sharing class PopupCreateAccountController {
    
    public PopupCreateAccountController() {
        
    }
    
    public void createAccount() {
        Account account = new Account(
            Name = 'AAA'
        );
        insert account;
    }
}

 

 Regards,

VaasuVaasu
Use below Javascript after saving the record.
Window.parent.location.reload();
self.close();
YuvikaYuvika
Hi Taiki,

Thanks for sending me the code.

I have put this in my parent page


extensions="PotentiallyLinkedApplicationsExt">


action="{!getCommentsDetail}" reRender="form" />>





value="Add Comment"/>



When I click on AddComment, I feel as its refreshing the current page but
no pop window is being opened

Thanks
Yuvika

--
Thanks & Regards,
Yuvika Aggarwal

--


Spread betting and CFD trading carry a high level of risk to your capital
and can result in losses that exceed your initial deposit. They may not be
suitable for everyone, so please ensure that you fully understand the risks
involved.

London Capital Group Ltd (LCG) is a company registered in England and Wales
under registered number: 3218125. LCG is authorised and regulated (number
182110) by the Financial Conduct Authority (FCA). LCG is a wholly owned
trading subsidiary of London Capital Group Holdings plc (LCGH plc) which is
registered in England and Wales under registered number: 05497744. The
registered address for LCG and LCGH plc is: 2nd Floor, 6 Devonshire Square,
London, EC2M 4AB.

Any information supplied in this email is not advice and is intended for
information purposes only. All information in this email is correct at the
time of publication.

Opinions, conclusions (etc.) that do not relate to the official business of
this company shall be understood as neither given nor endorsed by it.

This email contains confidential information or information belonging to
LCG and is intended solely for the addressees. The unauthorised disclosure,
use, dissemination or copying (either whole or partial) of this email, or
any information it contains, is prohibited. Emails are susceptible to
alteration and their integrity cannot be guaranteed. LCG shall not be
liable for this email if modified or falsified. If you are not the intended
recipient of this email, please delete it immediately from your system and
notify the sender of the wrong delivery and the mail deletion.

The contents of an attachment to this email may contain software viruses
which could damage your own computer system. Whilst steps have been taken
to minimise this risk, we do not accept liability for any damage which you
sustain as a result of software viruses. You should carry out your own
virus checks in keeping with good computing practice.

Please also note that email is not a secure method of communication.
YuvikaYuvika
Hi,
What code should I write to save it before writing these lines of code.
I tried this but it does not work


function popup()
{
save();
Window.parent.location.reload();
self.close();

}


--
Thanks & Regards,
Yuvika Aggarwal

--


Spread betting and CFD trading carry a high level of risk to your capital
and can result in losses that exceed your initial deposit. They may not be
suitable for everyone, so please ensure that you fully understand the risks
involved.

London Capital Group Ltd (LCG) is a company registered in England and Wales
under registered number: 3218125. LCG is authorised and regulated (number
182110) by the Financial Conduct Authority (FCA). LCG is a wholly owned
trading subsidiary of London Capital Group Holdings plc (LCGH plc) which is
registered in England and Wales under registered number: 05497744. The
registered address for LCG and LCGH plc is: 2nd Floor, 6 Devonshire Square,
London, EC2M 4AB.

Any information supplied in this email is not advice and is intended for
information purposes only. All information in this email is correct at the
time of publication.

Opinions, conclusions (etc.) that do not relate to the official business of
this company shall be understood as neither given nor endorsed by it.

This email contains confidential information or information belonging to
LCG and is intended solely for the addressees. The unauthorised disclosure,
use, dissemination or copying (either whole or partial) of this email, or
any information it contains, is prohibited. Emails are susceptible to
alteration and their integrity cannot be guaranteed. LCG shall not be
liable for this email if modified or falsified. If you are not the intended
recipient of this email, please delete it immediately from your system and
notify the sender of the wrong delivery and the mail deletion.

The contents of an attachment to this email may contain software viruses
which could damage your own computer system. Whilst steps have been taken
to minimise this risk, we do not accept liability for any damage which you
sustain as a result of software viruses. You should carry out your own
virus checks in keeping with good computing practice.

Please also note that email is not a secure method of communication.