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
Madhura BMadhura B 

Inline Editing for Lookup on VF page

Hi,

 

I have inline editing to one of the fields (lookup field to Contact) of a Custom object in my VF page.

When i double click the field, enter a value and hit save it is saving a null value. It works sometimes but not always.

 

I can't figure out why the inconsistency.

 

Please suggest. Following is my code.

 

<td >
    
    <apex:outputField value="{!fl.EventInfo.Facilitator_1__c}">
    <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton"/>
    </apex:outputField>
    <apex:outputField value="{!fl.SessionInfo.Facilitator1__c}"> 
    <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton"/>
    </apex:outputField>

</td>

 EventInfo and SessionInfo are my wrapper classes. Facilitator_1__c and Facilitator1__c are lookup to contact.

deepabalisfdcdeepabalisfdc

Hello,

<apex:PageBlock  id="pageBlock" mode="inlineEdit">
<apex:PageBlockSection title="" columns="1" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" id="saveButton" action="{!savedata}" />
</apex:pageBlockButtons>
<apex:inputField value="{!fl.EventInfo.Facilitator_1__c}"/>
<apex:outputField value="{!fl.EventInfo.Facilitator_1__c}" label="lookupfield">
<apex:inlineEditSupport showOnEdit="saveButton" event="ondblclick" changedStyleClass="myBoldClass" />
</apex:outputField>
</apex:PageBlockSection>
</apex:PageBlock>

 

Madhura BMadhura B

Thanks Deepabali
However it shows the input field on the page. I want that to appear only on double clicking. Can you please suggest something?

asish1989asish1989

Hi madhura

I think you are displaying these filed inside Pageblock table or data table of wrapper class list.So you need to add a check box inside that table to select particular record in which you want to edit by inline editing support,

 

Here is some code for your reference 

<apex:page StandardController="Contact" extensions="ListContactController" showHeader="false">
   <style type="text/css">
         .showline:hover
         { text-decoration: underline;
             color: blue;
            }  
     </style>
     <apex:pageMessages />
     <apex:form id="theForm">
        <apex:pageBlock Title="ALL CONTACTS">
          <apex:commandButton value="Save" action="{!Save}" id="SaveButton"  />
              <apex:outputPanel layout="block" styleClass="container">   
                    <apex:pageBlockTable value="{!Contacts}" width="100%" var="c" cellpadding="2" border="1"  rowClasses="odd,even" styleClass="tableClass" id="opp_table">
                         <apex:column headerValue="All contact Name"  styleClass="showline">
                              <apex:inputcheckbox value="{!c.selected}"   >
                                  <apex:actionSupport event="onclick" action="{!getSelected}" rerender="Selected_PBS"/>
                             </apex:inputcheckbox>&nbsp;
                              <b>
                                 <apex:commandLink value="{!c.con.Name}"  style="text-decoration:none;"  action="{!go}" title="for contact details">
                                      <apex:param name="conId" value="{!c.con.id}" />
                                 </apex:commandLink>
                              </b> </apex:column>
                         <apex:column headervalue="AccountName" styleClass="showline">
                               <b>
<apex:outputField value="{!c.con.AccountId}" > </apex:outputField> </b> </apex:column> <apex:column headerValue="ContactNo" > <apex:outputfield value="{!c.con.MobilePhone}" /> </apex:column> <apex:column headerValue="Email"> <apex:outputField value="{!c.con.Email}"/> </apex:column> <apex:inlineEditSupport event="ondblClick" showOnEdit="SaveButton" hideOnEdit="massdelete"/> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>

 Here is the Controller 

/**
*@purpose : Apex Controller resposible for displaying all contact in a pageblock table form where we can delete edit contact 
*@author :  Ashis.behera 
**/
public class ListContactController {

     //variable to hold Contact Record and id
     public Contact contact{get;set;}
     public Id contactId{get;set;}
     
     //wrapperlist variable to hold contact
     List<ContactWrapper> contactList = new List<ContactWrapper>();
     
     //varibale for list of contact records which are selected for mass delete
     List<Contact> selectedContacts = new List<Contact>();
      public List<Contact> test{get;set;}
     
     /**
    *@purpose : Standard Parameterised Constructor to create Contact Reference
    **/
     public ListContactController(ApexPages.StandardController controller) {
         Contact contact = new Contact();
         test = new List<Contact>();
        }
     
      /**
       *@purpose : Method to display contacts in a table 
       *@Param : None 
       *@Return : List<contactwrapper>
      **/
        public  List<ContactWrapper> getContacts() {
            for(Contact c: [SELECT Id,Name,Accountid,Account.Name,MobilePhone,Email FROM Contact ORDER BY createdDate DESC]){
                contactList.add(new ContactWrapper(c));
             }   
                return contactList;
        }
        
        /**
         *@purpose : Method to hold selected contacts  
         *@Param : None 
         *@Return : Pagereference
         **/
          public PageReference getSelected() {
              System.debug('======Inside the Get Function======');
              selectedContacts.clear();
              
              //adding contacts in list 
              for(ContactWrapper conWrapper: contactList) {
                 if(conWrapper.selected == true) {
                     selectedContacts.add(conWrapper.con); 
                  }
               }      
              return null;
          }
          
        //getting selected contacts
          public List<Contact> getSelectedContacts() {
              if(selectedContacts.size()>0) {
                  return selectedContacts;
               }  
               else {
                   return null;
               } 
          } 
           
        /**
         *@purpose : Method to save records from inline edit  
         *@Param : None 
         *@Return : Pagereference
         **/
          public PageReference Save() { 
              System.debug('******Inside ****** '+selectedContacts.size()+selectedContacts);
              update selectedContacts;
                 
              PageReference listContact=new PageReference('/apex/ListContact');
              listContact.setRedirect(true);
              return listContact;
           }
             
         /**
          *@purpose : Method to redirect to standard contact detail page    
          *@Param : None 
          *@Return : Pagereference
          **/
          public PageReference go() {
          
              //getting contact id form Url
              contactId= ApexPages.currentPage().getParameters().get('conId');
              contact =[SELECT Id,Name,Account.Name,MobilePhone,Email FROM Contact WHERE Id =: contactId];
              return (new ApexPages.StandardController(contact)).view();
          }
            
         /**
          *@purpose : wrapper class to use check box inside the table   
          *@author :  Ashis.behera 
         **/
         public class ContactWrapper {
             public Contact con{get; set;}
             public Boolean selected{get; set;}
             public ContactWrapper(Contact c) {
                con = c;
                selected = false;
             }
         }
        
          /**
           *@Purpose : Test Method to achieve Code Coverage and handeling exception
           *@Param : None 
           *@Return : void
           **/
          private static testmethod void t1() {
               test.startTest();
               Contact conTest = new Contact(LastName = 'asish',Phone = '1111111111');
               insert conTest;
               ApexPages.StandardController sc = new ApexPages.StandardController(conTest);
               Listcontactcontroller  ptest = new ListContactController(sc);
               ptest.getContacts();
               ptest.getSelected();
               ptest.getSelectedContacts();
               ptest.Save();
               System.currentPageReference().getParameters().put('conId',conTest.Id);
               System.currentPageReference().getParameters().put('conId',conTest.Id);
               ptest.go();
               System.currentPageReference().getParameters().put('conId',conTest.Id);
               ptest.redirect();
               test.stopTest();
               
           }
  }

 Let me know if it works 

 

If ths post solves your problem then please mark it as solutions so that others get benifited, If this post really helps you then hit kudos icon . 

 

   Thanks