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
tulasiram chtulasiram ch 

I am getting error when trying to close popup window when clicks on save/cancel please help me

Hi i used below code but its not working fine
1. Only one account record is displaying in first page
2.Popup window is not closing after record update or cancel.

Below is my code:
Page1:
<apex:page standardController="Account" recordSetVar="accs">
<script>
  function OpenVfpage(pid){
      var newwindow = window.open('/apex/Accsmallpopup?id='+pid, 'name=_blank','height=500,width=500,left=250,top=100'); 
  newwindow.focus();
 }
</script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a" >
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column id="two">
                    <apex:commandButton value="Click" onclick="OpenVfpage('{!a.id}')" reRender="two"/>
               </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Page2:
<apex:page controller="Accpopup2" showHeader="false" sidebar="false" id="the">
   <apex:form id="page">
    <apex:pageblock id="close">
    <apex:pageBlockSection >
        <apex:inputfield value="{!a.Name}"/>
         <apex:inputfield value="{!a.Phone}"/>
     </apex:pageBlockSection>
        <apex:pageblockbuttons >
        <apex:commandButton value="save" action="{!save}"/>
        <apex:commandButton value="cancel" action="{!cancel}"/>
            </apex:pageblockbuttons>
            <apex:inputHidden id="pass" value="{!status}"/>
             </apex:pageblock>
        
            <script language="JavaScript" type="text/javascript">
            if(document.getElementById('the:page:close:pass').getAttribute('value') == 'true')
                {
                    window.top.close();
                }
            </script>   
             </apex:form>
</apex:page>

Controller: 
public class Accpopup2 
{
    public Account a {get;set;}
    public string status {get;set;}
    public Accpopup2()
    {
      a = new account();  
    }
    public pagereference save()
    {
    ID caseID = apexpages.currentPage().getParameters().get('id');
    if(caseid!=null)
    {
        account acc = [select Name,Phone from account where ID =: caseID];
        acc.Name = a.Name;
        acc.Phone = a.Phone;
        update acc;
    }
       
        return null;
    }
    
    public pagereference cancel()
    {
        status = 'true';
          return null;    
    }
}
Best Answer chosen by tulasiram ch
Shashikant SharmaShashikant Sharma
Hi,

Change your page2 code to this
 
<apex:page controller="Accpopup2" showHeader="false" sidebar="false" id="the">
   <apex:form id="page">
    <apex:pageblock id="close">
    <apex:pageBlockSection >
        <apex:inputfield value="{!a.Name}"/>
         <apex:inputfield value="{!a.Phone}"/>
     </apex:pageBlockSection>
        <apex:pageblockbuttons >
        <apex:commandButton value="save" action="{!save}"/>
        <apex:commandButton value="cancel" immediate="true" onclick="return closePopUp(true);" action="{!cancel}"/>
            </apex:pageblockbuttons>
            <apex:inputHidden id="pass" value="{!status}"/>
             </apex:pageblock>
        
             <script language="JavaScript" type="text/javascript">
                closePopUp( false ); 
                function closePopUp( closePopUpWin ) {
                    if( closePopUpWin || document.getElementById('the:page:close:pass').getAttribute('value') == 'true') {
                        
                        window.top.close();
                    }
                    return false;
                }
             </script>   
               
             </apex:form>
</apex:page>
Change is that on Cancel button i made the immediate="true" onclick="return closePopUp(true);"

Which ignores required field validation on UI and closes the window.

Thanks
Shashikant


 

All Answers

Shashikant SharmaShashikant Sharma
Hi,

Change your page2 code to this
 
<apex:page controller="Accpopup2" showHeader="false" sidebar="false" id="the">
   <apex:form id="page">
    <apex:pageblock id="close">
    <apex:pageBlockSection >
        <apex:inputfield value="{!a.Name}"/>
         <apex:inputfield value="{!a.Phone}"/>
     </apex:pageBlockSection>
        <apex:pageblockbuttons >
        <apex:commandButton value="save" action="{!save}"/>
        <apex:commandButton value="cancel" immediate="true" onclick="return closePopUp(true);" action="{!cancel}"/>
            </apex:pageblockbuttons>
            <apex:inputHidden id="pass" value="{!status}"/>
             </apex:pageblock>
        
             <script language="JavaScript" type="text/javascript">
                closePopUp( false ); 
                function closePopUp( closePopUpWin ) {
                    if( closePopUpWin || document.getElementById('the:page:close:pass').getAttribute('value') == 'true') {
                        
                        window.top.close();
                    }
                    return false;
                }
             </script>   
               
             </apex:form>
</apex:page>
Change is that on Cancel button i made the immediate="true" onclick="return closePopUp(true);"

Which ignores required field validation on UI and closes the window.

Thanks
Shashikant


 
This was selected as the best answer
tulasiram chtulasiram ch
Hi shashikant thank you very much its, working fine. But  i have another issue with first page, it displaying only one Account record in the main page. Please identify the error.
Shashikant SharmaShashikant Sharma
Hi Tulsiram,

I do see different accounts at my side. So there is no issue that i see.

As the popup issue is fixed I would suggest to mark this question as resolved so others could be benifitted from it and open a new question thread for the new issue with more details.

User-added image
tulasiram chtulasiram ch
Sorry i got it, changed list view to all accounts on account tab . Thanks a lot.
tulasiram chtulasiram ch
Shashikant it is not refreshing the updated account after window close how can we do that.