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

action function not firing

So I created a custom lookup to provide a search functionality for a contact insert/edit table. The idea is that the user can "load"an existing contact instead of creating a duplicate in the system. When the lookup page is opened, the user does a search for a contact and when they click on the contact they want, the page calls the parent page's closeLookupPopup() method which would close the popup page. The method calls an actionfunction after doing the closing of the popup but the loadContact() actionfunction is either not getting called or the action method within it. I am not sure what is wrong with this so reaching out to someone who can help.
main VF pg:
<tbody> <apex:actionFunction action="{!loadCompContactInfo}" name="loadContact" reRender="contCompPanel,guarCompPanel,msgs,msgsBtn" > </apex:actionFunction> <apex:repeat var="cont" value="{!editCompanyWrapper.companycontactWrappers}"> <tr> <td> <apex:inputtext value="{!cont.contactId}" id="targetId" /> <apex:inputText value="{!cont.contactName}" id="targetName" > <apex:actionSupport event="onchange"> <apex:param assignTo="{!contWrpId}" name="wrpId" value="{!cont.ContactId}"></apex:param> </apex:actionSupport> </apex:inputText> <a href="#" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}'); return false">Search Contact</a> </td> <td class="slds-truncate"> <apex:inputField styleclass="slds-input" value="{!cont.contact.FirstName}"/> </td> <td class="slds-truncate"> <apex:inputField styleclass="slds-input" value="{!cont.contact.LastName}"/> </td> <td class="slds-truncate"> <apex:inputField styleclass="slds-input" value="{!cont.contact.Email}"/> </td> <td class="slds-truncate"> <apex:inputField styleclass="slds-input" value="{!cont.contact.MobilePhone}"/> </td> <td class="slds-truncate"><apex:inputCheckbox style="zoom: 150%" value="{!cont.acr.Designated_Signer__c}" /></td> <td class="slds-truncate"><apex:inputText value="{!cont.RoutingOrder}" /></td> <td class="slds-truncate"><apex:inputCheckbox style="zoom: 150%" value="{!cont.contact.Active__c}" /></td> <td class="slds-truncate"> <apex:actionRegion > <apex:commandButton action="{!deleteContact}" title="Remove Contact" value="Remove" styleclass="slds-button slds-button_destructive delBtn" reRender="contCompPanel,msgs,msgsBtn" rendered="{!cont.isNew == true}" > <apex:param value="{!cont.contact.Id}" assignTo="{!contId}" name="contactId" /> </apex:commandButton> </apex:actionRegion> </td> </tr> </apex:repeat> </tbody> //javascript in vf page var newWin=null; function openLookupPopup(name, id){ var url="/apex/LookupContactPopup?namefield=" + name + "&idfield=" + id; newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); if (window.focus) { newWin.focus(); } return false; } function closeLookupPopup(){ if (null!=newWin) { console.log('### closeLookpupPopup'); newWin.close(); console.log('### closeLookpupPopup after close'); loadContact(); console.log('### closeLookpupPopup after loadContact'); } }

//javascript in vf page 
var newWin=null; 
function openLookupPopup(name, id){ 
    var url="/apex/LookupContactPopup?namefield=" + name + "&idfield=" + id; 
    newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); 
    if (window.focus) { newWin.focus(); } 
    return false; 
} 
function closeLookupPopup(){ 
    if (null!=newWin) { 
        console.log('### closeLookpupPopup'); 
        newWin.close(); 
        console.log('### closeLookpupPopup after close'); 
        loadContact(); 
        console.log('### closeLookpupPopup after loadContact'); 
    } 
}//if I put loadContact() before newWin.close() then the popup doesn't close and the actionfunction is not fired, otherwise the close popoup works but not the actionfunction

controller methods in use:
public Id contWrpId  {get;set;}
//I've tried this methods return type as PageReference and also void but both dont work
public void loadCompContactInfo (){
    //if there is a selected contact, load the ACR and Contact info onto the GUaranteeContactWrapper
    system.debug('[loadCompContactInfo] contWrpId:' + contWrpId);
    system.debug('[loadCompContactInfo] companycontactWrappers:' + editCompanyWrapper.companycontactWrappers);
    if(contWrpId != null)
    for(GuaranteeContactWrapper gcw: editCompanyWrapper.companycontactWrappers){
        if(contWrpId  == gcw.contact.id){
            Contact sfcont = [Select id, AccountId, FirstName, LastName, Email, MobilePhone From Contact Where Id = :contWrpId limit 1];
            gcw.contact = sfCont;
            gcw.acr.ContactId = sfCont.id; 
        }
    }   
}
popup Vf pg:
<apex:page controller="LookupContactPopupController" sidebar="false" showheader="false">
<script language="javascript">
   window.onload = new function() { 
      // bring popup window to front
      window.focus(); 
      var ele=document.getElementById('{!$Component.form.block.section.query}');
      if (ele)
      {
         ele.focus();
      }
   }
   
   function fillIn(name, id){
      var winMain=window.opener;
      if (null==winMain)
      {
         winMain=window.parent.opener;
      }
      var ele=winMain.document.getElementById('{!$CurrentPage.parameters.namefield}');
      ele.value=name;
      ele=winMain.document.getElementById('{!$CurrentPage.parameters.idfield}');
      ele.value=id;
      CloseWindow();
   }

   function CloseWindow(){
      var winMain=window.opener;
      if (null==winMain)
      {
         winMain=window.parent.opener;
      }
       
      winMain.closeLookupPopup();
   }
</script>

  <apex:messages />
  <apex:form id="form">  
        
     <div style="width 100%">
        <apex:pageBlock title="Lookup" id="block">
           
          <apex:pageBlockSection id="section">
              Enter search text and click Go<br/>
              <apex:inputText value="{!query}" id="query"/> 
              <apex:commandButton value="Go" action="{!runQuery}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>

        <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:pageBlockTable value="{!contacts}" var="contact">
                <apex:column headerValue="Name">
                  <apex:outputLink value="#" onclick="fillIn('{!contact.Name}', '{!contact.id}')">{!Contact.Name}</apex:outputLink>       
                </apex:column>
                <apex:column headerValue="Street" value="{!contact.FirstName}"/>
                <apex:column headerValue="City" value="{!contact.LastName}"/>
                <apex:column headerValue="Account" value="{!contact.Account.Name}"/>
                <apex:column headerValue="Email" value="{!contact.Email}"/>
                <apex:column headerValue="Mobile Phone" value="{!contact.MobilePhone}"/>
              </apex:pageBlockTable>    
          </apex:pageBlockSection>
        </apex:pageBlock>
        <button type="button" onclick="CloseWindow();">Close Window</button>
     </div>
   </apex:form>
</apex:page>
popup controller:
public with sharing class LookupContactPopupController {
    public String query {get; set;}
    public List<Contact> contacts {get; set;}
    
    public PageReference runQuery()
    {
        List<List<Contact>> searchResults=[FIND :query IN ALL FIELDS RETURNING contact (id, accountId, Account.Name, firstname, lastName, name, email, mobilephone)];
        contacts=searchResults[0];
        return null;
    }
}