0

I have created a Custom Lookup Page for Contact and in that there are two tabs 1 for Search and another 1 is for adding the new Contact record. The fields in the new contact tab is coming from a fieldset. Refer Below screen shot

enter image description here

Problem:

While adding the new Contact record i have a Account lookup on the custom Contact Lookup page. When clicked on the magnifying glass beside Account Lookup it opens up the standard Account LookupPage but when we select any Account its unable to select the corresponding Account on the Custom Contact lookup Page.

First VF Page AccountContactRelation

<apex:page controller="AccountContactRelationController" id="Page" tabstyle="AccountContactRelation">

  <script type="text/javascript"> 
  function openLookup(baseURL, width, modified, searchParam){
    var originalbaseURL = baseURL;
    var originalwidth = width;
    var originalmodified = modified;
    var originalsearchParam = searchParam;

    var lookupType = baseURL.substr(baseURL.length-3, 3);
    if (modified == '1') baseURL = baseURL + searchParam;

    var isCustomLookup = false;

    // Following "003" is the lookup type for Contact object
    if(lookupType == "003"){

      var urlArr = baseURL.split("&");
      var txtId = '';
      if(urlArr.length > 2) {
        urlArr = urlArr[1].split('=');
        txtId = urlArr[1];
      }

      // Following is the url of Custom Lookup page. You need to change that accordingly
      baseURL = "/apex/CustomContactLookup?txt=" + txtId;

      // Following is the id of apex:form control "myForm". You need to change that accordingly
      baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
      if (modified == '1') {
        baseURL = baseURL + "&lksearch=" + searchParam;
      }

      // Following is the ID of inputField that is the lookup to be customized as custom lookup
      if(txtId.indexOf('Contact') > -1 ){
        isCustomLookup = true;
      }
    }


    if(isCustomLookup == true){
      openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    }
    else {
      if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
      openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    } 
  }
</script>

<apex:sectionHeader title="Account Contact Relationship Edit"  subtitle="New Account Contact Relationship" />

  <apex:form id="myForm">  
    <apex:PageBlock id="PageBlock" title="Account Contact Relationship Edit">        
      <apex:pageBlockSection columns="2">
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Account"/>
            <apex:inputField id="Account" value="{!accountContactRelation.AccountId}"  />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Roles"/>
            <apex:inputField id="Roles" value="{!accountContactRelation.Roles}"  />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Contact"/>
            <apex:inputField id="Contact" value="{!accountContactRelation.ContactId}"  />
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
      <apex:pageBlockButtons style="padding-left:13%">
            <apex:commandButton value="Save" rerender="myForm" id="SaveButton" action="{!save}" ></apex:commandButton>
            <apex:commandButton value="Save & Add" action="{!saveAndAdd}" rerender="myForm" ></apex:commandButton>
            <apex:commandButton value="Cancel" id="CancelButton" rerender="myForm" ></apex:commandButton>   
      </apex:pageBlockButtons>
    </apex:PageBlock>
  </apex:form>

</apex:page>

Second VF Page: CustomContactLookup

<apex:page controller="CustomContactLookupController" title="Search" showHeader="false" sideBar="false" tabStyle="Contact" id="pg">

  <apex:form >
  <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
    <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">

      <!-- SEARCH TAB -->
      <apex:tab label="Search" name="tab1" id="tabOne">

        <apex:actionRegion >  
          <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
            <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>
            <apex:inputText id="txtSearch" value="{!searchString}" />
              <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>
          </apex:outputPanel>

          <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
            <apex:pageBlock id="searchResults"> 
              <apex:pageBlockTable value="{!results}" var="a" id="tblResults">
                <apex:column >
                  <apex:facet name="header">
                    <apex:outputPanel >Name</apex:outputPanel>
                  </apex:facet>
                   <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>     
                </apex:column>
              </apex:pageBlockTable>
            </apex:pageBlock>
          </apex:outputPanel>
        </apex:actionRegion>

      </apex:tab>

      <!-- NEW CONTACT TAB -->
      <apex:tab label="New Contact" name="tab2" id="tabTwo">

        <apex:pageBlock id="newContact" title="New Contact" >

          <apex:pageBlockButtons >
            <apex:commandButton action="{!saveContact}" value="Save" reRender="newContact" />
          </apex:pageBlockButtons>
          <apex:pageMessages />

          <apex:pageBlockSection columns="2">
            <apex:repeat value="{!$ObjectType.Contact.FieldSets.CustomContactLookup}" var="f">
              <apex:inputField value="{!Contact[f]}" required="{!OR(f.required, f.dbrequired)}" />
            </apex:repeat>
          </apex:pageBlockSection> 
        </apex:pageBlock>

      </apex:tab>
    </apex:tabPanel>
  </apex:outputPanel>
  </apex:form>
</apex:page>

Any help will be appreciated.

1

The issue is due to the same window name "Lookup" which is used in your page and salesforce also usese the same window name so change the window name to something else then your customlookup window and standard lookup window will open in two diffrent window so it will work fyn.

openPopup(baseURL, "**lookup2**", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);

I hope it servers your requirement.

|improve this answer|||||
  • why are you adding multiple answers edit the original one if you think its right do not post multiple answers – RCS Mar 23 '17 at 10:38
  • hahaha ok I'm a new user so expect mistakes. – Safiya PV Mar 23 '17 at 10:39
  • It is not that only 1 page. I have 2 VF Page. 1. Custom VF page where the Contact Lookup is there on that CustomContactLookup page is opened in which there are 2 tabs 1. Search and 2. New Contact on New Contact i have fields coming from fieldset so out of which there is AccountId that needs to be captured while creating the Contact. So the problem is when i click on the Account lookup it opens up the standard Account Lookup Dialog and from there i want to select the Account lookup value to the CustomContactLookup page. – RCS Mar 23 '17 at 10:44
  • yea i understood. So can u share the code for both the tabs so that we don't have to do it from scratch. – Safiya PV Mar 23 '17 at 10:51
  • See the updated question with code details. – RCS Mar 23 '17 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.