Page2: 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.Phone = a.Phone; update acc; } return null; } public pagereference cancel() { status = 'true'; return null; } }", "answerCount": 5, "upvoteCount": 0, "datePublished": "2017-07-26T17:54:32.000Z", "author": { "@type": "Person", "name": "tulasiram ch", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000CTHU6AAP", "affiliation": { "@type": "Organization", "name": "--" } }, "acceptedAnswer": { "@type": "Answer", "text": "Hi, 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  ", "upvoteCount": 1, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4O5iSAF", "datePublished": "2017-07-27T03:30:28.000Z", "author": { "@type": "Person", "name": "Shashikant Sharma", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000Dq0ThQAJ", "affiliation": { "@type": "Organization", "name": "Self" } } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Shashikant it is not refreshing the updated account after window close how can we do that. ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4O5iSAF", "datePublished": "2017-07-27T12:05:17.000Z", "author": { "@type": "Person", "name": "tulasiram ch", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000CTHU6AAP", "affiliation": { "@type": "Organization", "name": "--" } } } ] } }
Skip to main content
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;    

    }

}
5 answers
  1. Jul 27, 2017, 3:30 AM
    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

     
0/9000