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

Object records are displayed in one page. Each record has one edit button when we click on that one popup will be diplayed.

Hi Folks,

But when i am clicking on button popup have not displayed. Please go through below code. Thanks in advance.

VF Page:

<apex:page controller="popup4" >
<style type="text/css">

.popup  
  {  
  background-color: orange;  
  border-width: 2px;  
  border-style: solid;  
  z-index: 9999;  
  left: 50%;  
  padding:10px;  
  position: absolute;  
  width: 400px;  
  margin-left: -250px;  
  top:80px;  
  }  
</style>
 <apex:form >
  <apex:pageBlock >
   <apex:pageBlockTable value="{!details}" var="ac">
    <apex:column value="{!ac.name}"/>
    <apex:column value="{!ac.phone}"/>
    
<apex:column headervalue="Details">
    <apex:commandButton value="Edit" action="{!edit}" />
    <apex:param name="id" value="{!ac.id}" assignTo="{!aid}"/>
    </apex:column>
    <apex:outputPanel >
    <apex:outputPanel styleClass="popup" rendered="{!displaypopup}"/>
    <apex:outputField value="{!ac.name}"/>
        <apex:outputField value="{!ac.phone}"/>
            <apex:outputField value="{!ac.Email__c}"/>
    </apex:outputPanel>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
   </apex:page>

Apex Class:

public with sharing class popup4 {

    public String aid { get; set; }
    public boolean displaypopup{set;get;}
    public list<account>acct{set;get;}
    
    public PageReference edit() 
    {
         displaypopup=true;
         string aid=apexpages.currentpage().getparameters().get('id');
         acct=[select id,name,phone,email__c from account where id=:aid];
         return null;
    }

  public list<account>details{set;get;}
    
    public popup4()
    {
     
     details=[select name,phone from account];
     }
}
Best Answer chosen by Salesforce 283
Darshan Shah2Darshan Shah2

Hi salesforce developer 31,

When we use commandButton without rerender attribute then apex:param will not work. (It is known issue to salesforce).
So resolution is to use commandLink.

In controller 'acct' is getter setter and is a list containing only one record, so we have used acct[0].name


If any of my above answers resolved your question then mark this question as 'SOLVED', so other people can get help from this.

Warm Regards,
Darshan Shah :)

All Answers

Darshan Shah2Darshan Shah2

Hi salesforce developer 31,

I am reposting your code with some updates: (put outputPanel outside the pageBlock and added param inside the commandButton).

Kindly let me know whether it works or not.

Page:
<apex:form>
        <apex:outputPanel id="opPopup">
             <apex:outputPanel styleClass="popup" rendered="{!displaypopup}">
                <apex:outputField value="{!acct[0].name}"/>
                <apex:outputField value="{!acct[0].phone}"/>
             </apex:outputPanel>
        </apex:outputPanel>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!details}" var="ac">
                <apex:column value="{!ac.name}"/>
                <apex:column value="{!ac.phone}"/>
                <apex:column headervalue="Details">
                    <apex:commandButton value="Edit" action="{!edit}" reRender="opPopup">
                        <apex:param name="id" assignTo="{!aid}" value="{!ac.id}" />
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>


Warm Regards,
Darshan Shah
Salesforce 283Salesforce 283
Hi Darshan, Popup has been displayed but fields are not shown in popup.
Darshan Shah2Darshan Shah2
Hi Salesforce developer 31,

Make output panel as below:

       <apex:outputPanel id="opPopup">
             <apex:outputPanel styleClass="popup" rendered="{!displaypopup}">
                 <apex:outputLabel value="Name: " />
                 <apex:outputField value="{!acct[0].name}"/><br/>
                 <apex:outputLabel value="Phone: " />
                 <apex:outputField value="{!acct[0].phone}"/>
             </apex:outputPanel>
        </apex:outputPanel>

If page is displaying some records with values then clicking on 'Edit' will also show some values.
Please check screenshot from my org below:

User-added image

Kindly let me know if you need more information.

Regards,
Darshan
Salesforce 283Salesforce 283
Hi Darshan, When click the button i have got a below error message. [image: Inline image 1]
Darshan Shah2Darshan Shah2
Hi Salesforce developer 31, I am not able to see above image.
Salesforce 283Salesforce 283
Hi darshan, Pls see the below error msg. "Subscript is invalid because list is empty".
Darshan Shah2Darshan Shah2
Yes I got the error.. Account Id is not going from page to controller.

Try to make commandButton to commandLink
OR
you can post your class and page here so I can help.
Salesforce 283Salesforce 283
Hi Darshan, I got it when changed to commandLink. How it would come and why we have used acc[0].name and commandLink instead of commandbutton.
Darshan Shah2Darshan Shah2

Hi salesforce developer 31,

When we use commandButton without rerender attribute then apex:param will not work. (It is known issue to salesforce).
So resolution is to use commandLink.

In controller 'acct' is getter setter and is a list containing only one record, so we have used acct[0].name


If any of my above answers resolved your question then mark this question as 'SOLVED', so other people can get help from this.

Warm Regards,
Darshan Shah :)
This was selected as the best answer