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
KS KumaarKS Kumaar 

visual force page along with popup window

Let say we are performing on Account object

User-added image

On my visualforce page i have a button for each and every record as shown in image, on click of this button i want to open a pop up window. In whcih popup window should conatins account name and phone fields and save and cancel buttons only. Later by entering the values for account name and phone fields, if i click on save button, the values should be populated in perticular record(Should be modified in respected record). If i click on cancel button the popup window should be closed.

For this process, i tried several times with out success by using following code
<apex:page standardController="Account" recordSetVar="accs">
<script>
  function OpenVfpage(pid){
  var newwindow = window.open('/'+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>

This code is giving one popup window which conatins a detailed page of a record. but this is not reqiurement.

can you please share your thoughts along with code???

Thanking you 

KS Kumaar
Best Answer chosen by KS Kumaar
VamsiVamsi
Hi Kumaar,

Please create another vf page to display the pop-up with the fields you specified. It will update the account records when clicked on save and closes the pop-up when clicked on cancel button .

Please try the below code and let me know if it helps you.

Below is new VF page code with controller 

#VFpage


<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;    
    }
}


Yours Modified VF page 

<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>

Please mark as best answer, If it solves your problem.

All Answers

VamsiVamsi
Hi Kumaar,

Please create another vf page to display the pop-up with the fields you specified. It will update the account records when clicked on save and closes the pop-up when clicked on cancel button .

Please try the below code and let me know if it helps you.

Below is new VF page code with controller 

#VFpage


<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;    
    }
}


Yours Modified VF page 

<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>

Please mark as best answer, If it solves your problem.
This was selected as the best answer
SelvaRathinamSelvaRathinam
Great ! its worked