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
kpriya Aggarwalkpriya Aggarwal 

Hi, It's urgent please can anyone help me on this?

VF Page
<apex:page Controller="Contactsrd" sidebar="false">  
  <style type="text/css">  
  .popup {  
  background-color: White;  
  border-width: 2px;  
  border-style: solid;  
  z-index: 9999;  
  left: 50%;  
  padding:10px;  
  position: absolute;  
  width: 400px;  
  margin-left: -250px;  
  top:80px;  
  }  
  .popupBg{  
  background-color:grey;  
  opacity: 0.20;  
  filter: alpha(opacity = 70);  
  position: absolute;  
  width: 100%;  
  height: 100%;  
  top: 0;  
  left: 0;  
  z-index: 9998;  
  }  
  </style>  
  <apex:form id="form">  
  <apex:pageblock id="pb">   
  <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
  <apex:column headerValue="Contact Name">  
  <apex:outputText value="{!ct.name}"></apex:outputText>   
  </apex:column>  
  <apex:column headerValue="Detail">  
  <apex:outputPanel >  
  <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
  <input type="radio" name="det" />  
  <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
  </apex:actionSupport>  
  </apex:outputPanel>  
  </apex:column>  
  </apex:pageBlockTable>  
 </apex:pageblock>  
 <!--popup code starts-->  
  <apex:outputPanel id="popup">  
  <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
  <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
  <apex:messages />  
  <center><h2>{!ct_name} Information</h2></center>  
  <apex:panelGrid columns="2" >  
  <apex:outputLabel value="Contacts"/>
      <apex:inputText value="{!ct_name}"></apex:inputText>
  <apex:commandButton value="Update" action="{!updaterec}"/>  
  <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
  </apex:panelGrid>
      
  </apex:outputPanel>  
  </apex:outputPanel>  
 <!-- end of popup code-->  
  </apex:form>  
 </apex:page>
Controller:
public class Contactsrd{
  Public String ct_name { get; set; }  
  public boolean displayPopUp { get; set; }  
  Contact cont {get; set;}
   List<Contact> clist= new List<Contact>();
     //cont= new contact();
 public PageReference closePopup() {//hide method  
  displayPopup = false;  
  return null;  
  }  
 public PageReference detailPage() {// action method which shows popup on selection  
  displayPopup = true;  
  system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
  String id = ApexPages.currentPage().getParameters().get('id'); 
  Contact ac = [select id,name from Contact where id =: id];
  ct_name = ac.name; 
  //update ac;
  return null;  
  }  
  public list<Contact> getGetContactt() {  
  list<Contact> ctl = [select id,name from Contact];  
  return ctl;  
  }  
  public Contactsrd(){
  Id id= ApexPages.currentPage().getParameters().get('id');
  cont=(id==null)? new Contact():[Select lastName FROM Contact Where Id= :id];
  }
 public PageReference updaterec() {//update popup record   
  //displayPopup = true; 
  Try{upsert(cont);}catch(system.DMLException e){ApexPages.addMessages(e); return null;}
  //try{
  //contact c= [SELECT Id FROM Contact WHERE Id=:id];
  //c.Salutation= ct_name;
  //c.FirstName=ct_name;
  //c.LastName=ct_name;
  //update cont;
  return null;  
  }  
  }
See below image.I got an error while upserting record.

User-added image
Best Answer chosen by kpriya Aggarwal
Raj VakatiRaj Vakati
Use this code
 
public class Contactsrd{
    Public String ct_name { get; set; }  
    Public String id { get; set; }  
    
    public boolean displayPopUp { get; set; }  
    public Contact cont {get; set;}
    List<Contact> clist= new List<Contact>();
    //cont= new contact();
    public PageReference closePopup() {//hide method  
        displayPopup = false;  
        return null;  
    }  
    public PageReference detailPage() {// action method which shows popup on selection  
        displayPopup = true;  
        system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
         id = ApexPages.currentPage().getParameters().get('id'); 
        Contact ac = [select id,name from Contact where id =: id];
        ct_name = ac.name; 
        //update ac;
        return null;  
    }  
    public list<Contact> getGetContactt() {  
        list<Contact> ctl = [select id,name from Contact];  
        return ctl;  
    }  
    public Contactsrd(){
      //  Id id= ApexPages.currentPage().getParameters().get('id');
        if(ct_name==null){
            ct_name ='No Last Name ';
        }
        //System.debug('id-->>'+id) ;
       
            }
    public PageReference updaterec() {//update popup record   
        //displayPopup = true; 
        Try{
             cont=(id==null)? 
                 new Contact(lastname =ct_name ):new Contact(lastname =ct_name ,Id=id);
             System.debug('id-->>'+id) ;
             System.debug('ct_name-->>'+ct_name) ;
            upsert cont ;
        }catch(system.DMLException e){ApexPages.addMessages(e); return null;}
        //try{
        //contact c= [SELECT Id FROM Contact WHERE Id=:id];
        //c.Salutation= ct_name;
        //c.FirstName=ct_name;
        //c.LastName=ct_name;
        //update cont;
        return null;  
    }  
}
 
<apex:page Controller="Contactsrd" sidebar="false">  
    <style type="text/css">  
        .popup {  
        background-color: White;  
        border-width: 2px;  
        border-style: solid;  
        z-index: 9999;  
        left: 50%;  
        padding:10px;  
        position: absolute;  
        width: 400px;  
        margin-left: -250px;  
        top:80px;  
        }  
        .popupBg{  
        background-color:grey;  
        opacity: 0.20;  
        filter: alpha(opacity = 70);  
        position: absolute;  
        width: 100%;  
        height: 100%;  
        top: 0;  
        left: 0;  
        z-index: 9998;  
        }  
    </style>  
    <apex:form id="form">  
        <apex:pageblock id="pb">   
            <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
                <apex:column headerValue="Contact Name">  
                    <apex:outputText value="{!ct.name}"></apex:outputText>   
                </apex:column>  
                <apex:column headerValue="Detail">  
                    <apex:outputPanel >  
                        <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
                            <input type="radio" name="det" />  
                            <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
                        </apex:actionSupport>  
                    </apex:outputPanel>  
                </apex:column>  
            </apex:pageBlockTable>  
        </apex:pageblock>  
        <!--popup code starts-->  
        <apex:outputPanel id="popup">  
            <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
            <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
                <apex:messages />  
                <center><h2>{!ct_name} Information</h2></center>  
                <apex:panelGrid columns="2" >  
                    <apex:outputLabel value="Contacts"/>
                    <apex:inputText value="{!ct_name}"></apex:inputText>
                    <apex:commandButton value="Update" action="{!updaterec}"/>  
                    <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
                </apex:panelGrid>
                
            </apex:outputPanel>  
        </apex:outputPanel>  
        <!-- end of popup code-->  
    </apex:form>  
</apex:page>

 

All Answers

Raj VakatiRaj Vakati
Use the below code.  The problem is when you are trying to update a contact without passing URL parameters 
 
public class Contactsrd{
    Public String ct_name { get; set; }  
    public boolean displayPopUp { get; set; }  
    public Contact cont {get; set;}
    List<Contact> clist= new List<Contact>();
    //cont= new contact();
    public PageReference closePopup() {//hide method  
        displayPopup = false;  
        return null;  
    }  
    public PageReference detailPage() {// action method which shows popup on selection  
        displayPopup = true;  
        system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
        String id = ApexPages.currentPage().getParameters().get('id'); 
        Contact ac = [select id,name from Contact where id =: id];
        ct_name = ac.name; 
        //update ac;
        return null;  
    }  
    public list<Contact> getGetContactt() {  
        list<Contact> ctl = [select id,name from Contact];  
        return ctl;  
    }  
    public Contactsrd(){
        Id id= ApexPages.currentPage().getParameters().get('id');
        if(ct_name==null){
            ct_name ='No Contact';
        }
        cont=(id==null)? new Contact(lastname =ct_name ):[Select lastName FROM Contact Where Id= :id];
            }
    public PageReference updaterec() {//update popup record   
        //displayPopup = true; 
        Try{upsert(cont);}catch(system.DMLException e){ApexPages.addMessages(e); return null;}
        //try{
        //contact c= [SELECT Id FROM Contact WHERE Id=:id];
        //c.Salutation= ct_name;
        //c.FirstName=ct_name;
        //c.LastName=ct_name;
        //update cont;
        return null;  
    }  
}

 
kpriya Aggarwalkpriya Aggarwal
Hi Raj,
Thanks for your response.
Only error is resolved but changes are not done in record. Suppose record name is SDFC2 and am renaming with TCS. TCS is not exist in contacts' records.
Raj VakatiRaj Vakati
Use this code
 
public class Contactsrd{
    Public String ct_name { get; set; }  
    Public String id { get; set; }  
    
    public boolean displayPopUp { get; set; }  
    public Contact cont {get; set;}
    List<Contact> clist= new List<Contact>();
    //cont= new contact();
    public PageReference closePopup() {//hide method  
        displayPopup = false;  
        return null;  
    }  
    public PageReference detailPage() {// action method which shows popup on selection  
        displayPopup = true;  
        system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
         id = ApexPages.currentPage().getParameters().get('id'); 
        Contact ac = [select id,name from Contact where id =: id];
        ct_name = ac.name; 
        //update ac;
        return null;  
    }  
    public list<Contact> getGetContactt() {  
        list<Contact> ctl = [select id,name from Contact];  
        return ctl;  
    }  
    public Contactsrd(){
      //  Id id= ApexPages.currentPage().getParameters().get('id');
        if(ct_name==null){
            ct_name ='No Last Name ';
        }
        //System.debug('id-->>'+id) ;
       
            }
    public PageReference updaterec() {//update popup record   
        //displayPopup = true; 
        Try{
             cont=(id==null)? 
                 new Contact(lastname =ct_name ):new Contact(lastname =ct_name ,Id=id);
             System.debug('id-->>'+id) ;
             System.debug('ct_name-->>'+ct_name) ;
            upsert cont ;
        }catch(system.DMLException e){ApexPages.addMessages(e); return null;}
        //try{
        //contact c= [SELECT Id FROM Contact WHERE Id=:id];
        //c.Salutation= ct_name;
        //c.FirstName=ct_name;
        //c.LastName=ct_name;
        //update cont;
        return null;  
    }  
}
 
<apex:page Controller="Contactsrd" sidebar="false">  
    <style type="text/css">  
        .popup {  
        background-color: White;  
        border-width: 2px;  
        border-style: solid;  
        z-index: 9999;  
        left: 50%;  
        padding:10px;  
        position: absolute;  
        width: 400px;  
        margin-left: -250px;  
        top:80px;  
        }  
        .popupBg{  
        background-color:grey;  
        opacity: 0.20;  
        filter: alpha(opacity = 70);  
        position: absolute;  
        width: 100%;  
        height: 100%;  
        top: 0;  
        left: 0;  
        z-index: 9998;  
        }  
    </style>  
    <apex:form id="form">  
        <apex:pageblock id="pb">   
            <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
                <apex:column headerValue="Contact Name">  
                    <apex:outputText value="{!ct.name}"></apex:outputText>   
                </apex:column>  
                <apex:column headerValue="Detail">  
                    <apex:outputPanel >  
                        <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
                            <input type="radio" name="det" />  
                            <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
                        </apex:actionSupport>  
                    </apex:outputPanel>  
                </apex:column>  
            </apex:pageBlockTable>  
        </apex:pageblock>  
        <!--popup code starts-->  
        <apex:outputPanel id="popup">  
            <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
            <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
                <apex:messages />  
                <center><h2>{!ct_name} Information</h2></center>  
                <apex:panelGrid columns="2" >  
                    <apex:outputLabel value="Contacts"/>
                    <apex:inputText value="{!ct_name}"></apex:inputText>
                    <apex:commandButton value="Update" action="{!updaterec}"/>  
                    <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
                </apex:panelGrid>
                
            </apex:outputPanel>  
        </apex:outputPanel>  
        <!-- end of popup code-->  
    </apex:form>  
</apex:page>

 
This was selected as the best answer
kpriya Aggarwalkpriya Aggarwal
It's working!! Tank you so much Raj