You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
Change your page2 code to this
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
Change your page2 code to this
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
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.