1

I am working on a Custom Lookup which display list of records coming from external sytem. when users click/select on name column, a javascript function runs and update the name (text) on the parent window field. Now , I have to carry one more value of the selected record to the parent window but this column/value does not get displayed on UI.

    for example.. Custom Lookup display below rows, 
    now when use click xyz, I pick that text value and 
    update the field in parent window. But, there is externalId which is not being displayed on custom lookup, 
and I need to update that on parent window too.

          custom Lookup ( child Window) 
           Name  column1   column1 
            xyz    ---       ---        ExternalId1 (not on UI)
            abc    ----     ----        ExternalId2 (not on UI)

            Parent Window
            Name xyz  (I populate it when user click on xyz on custom lookup)
            External Id  -  how to populate this ??





<apex:page controller="customerLookUpController_HDSR2" sidebar="False" showHeader="False">
  <script>
       //window.opener.location.reload(true);
        function prospectClicked (){
            //window.opener.callJavaFunc(); //Commented to pre-populate company name
            var compName = document.getElementById('{!$Component.j_id0.frm.block_1.Section_1.Section_1_Item_1.section1Input_1}').value;
            //alert('********company name*********'+compName);

            //added a parameterized function to pre-populate company name and Toggle Prospect Account
            window.opener.populateCompanyName(compName); 
            window.close(); 
        }
    </script>

  <script type= "text/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) {
     var winMain=window.opener;
      if (null==winMain){
            winMain=window.parent.opener;
        }
      var ele=winMain.document.getElementById('{!$CurrentPage.parameters.namefield}');
      ele.value=name;
      CloseWindow();
   }

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

<!--Added by Badri for Prepopulation of Country-->

<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.0.min.js"></script>
<script>
    $(document).ready(function() {
            $('select[id*="selectCountries"]').val('United States') ;
        }
    );
</script>
   <apex:form id="frm">

        <c:ProcessingWindow />
        <apex:pageBlock id="block_1">
            <apex:pageBlockSection id="Section_1" title="Customer Search" columns="2" collapsible="False">
                <apex:pageBlockSectionItem id="Section_1_Item_1">
                    End User Account
                    <span style="color:red; font-weight:1200">*</span>
                    <apex:inputText id="section1Input_1" value="{!oCustomerSearch.sCustomerName}" label="Name" required="True"/>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    Country
                    <span style="color:red; font-weight:1200">*</span>
                    <apex:selectList id="selectCountries" value="{!oCustomerSearch.sCustomerCountry}" label="Country" required="True" multiselect="false" size="1">    
                        <apex:selectOptions value="{!selectCountry}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    Street Address
                    <apex:inputText value="{!oCustomerSearch.sCustomerStreetAddress}" label="streetAddress" />
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    City
                    <apex:inputText value="{!oCustomerSearch.sCustomerCity}" label="Address"/>
                </apex:pageBlockSectionItem> 

                <apex:pageBlockSectionItem >
                    State/Province
                    <apex:inputText value="{!oCustomerSearch.sCustomerState}" label="City"/>
                </apex:pageBlockSectionItem>   

                <apex:pageBlockSectionItem >
                    Zip/Postal Code
                    <apex:inputText value="{!oCustomerSearch.sCustomerPostalCode}" label="Postal"/>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    Site Id
                    <apex:inputText value="{!oCustomerSearch.sCustomerSiteId}" label="Site Id"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <!-- Buttons -->
             <apex:pageBlockButtons location="bottom" id="Buttonsection">
                 <apex:commandButton action="{!searchRecords}" value="Search" rerender="thepanel,PrButton" Status="waitingStatusLoad"/>
                 <apex:commandButton onclick="window.close();" action="{!closeWindow}" value="Cancel" immediate="True"/>
                 <apex:commandButton onclick="prospectClicked();" value="New Prospect" disabled="{!prospectDisableFlag}" id="PrButton" action="{!toggleProspectValue}"/>  
             </apex:pageBlockButtons>
         </apex:pageBlock>

            <!-- Table -->
          <apex:outputPanel Id="thepanel">
           <apex:pageMessages id="PgMessage"/>
          <apex:pageBlock >
            <apex:pageBlockTable id="pgtable" var="lst" value="{!dealRegCust.listOfCustomers}" columns="7" rendered="{!dealRegCust.listOfCustomers!= null && dealRegCust.listOfCustomers.size>0}"> 
                <apex:column headerValue="Customer Name" id="IdName">
                       <a href='javascript:fillIn("{!lst.sCustomerName }" )'>
                         {!lst.sCustomerName}
                      </a>
                </apex:column>
                <apex:column headerValue="Country">
                    {!(lst.sCustomerCountry)}
                </apex:column>
                <apex:column headerValue="Street Address" >
                    {!(lst.sCustomerStreetAddress)}
                </apex:column>
                <apex:column headerValue="City">
                    {!(lst.sCustomerCity)}
                </apex:column>
                <apex:column headerValue="State/Province">
                    {!(lst.sCustomerState)}
                </apex:column>
                <apex:column headerValue="Zip/Postal Code">
                    {!(lst.sCustomerPostalCode )}
                </apex:column>
                <apex:column headerValue="Site ID">
                    {!(lst.sCustomerSiteId)}
                </apex:column> 
                <apex:column headerValue="">
                     <apex:inputHidden value="{!lst.sCustomerRowId}"/>
                </apex:column>                                
            </apex:pageBlockTable>      
        </apex:pageBlock>
      </apex:outputPanel>  
    </apex:form> 
</apex:page>

Controller....

public class  customerLookUpController_HDSR2 {



 //Defining Variables   
    public Deal_Registration_HDS__c dealReg{get;set;}
    public Account acct;
    public boolean toggleProspect {get;set;}
    public dealRegistrationJSON_hds.customerSearchRequest  oCustomerSearch {get;set;}
    public list<dealRegistrationJSON_hds.customerSearchReponse> customerSearchResults{get;set;}
    public dealRegistrationJSON_hds dealRegCust{get;set;}
    public List<Account> accList {get;set;}
    public Boolean check {get;set;}
    public boolean prospectDisableFlag{get;set;}   
    public List<SelectOption> selectCountry; 

    public customerLookUpController_HDSR2 () {

       /*************initialization for Customer Lookup************/
        prospectDisableFlag = true;
        toggleProspect = true;
        oCustomerSearch = new dealRegistrationJSON_hds.customerSearchRequest();
     /***********************************************************/       

    }



    /******************************Methods for Customer Lookup***************************************/
    //for closing the window
    public void closeWindow(){

    }
   //for populating Country List
    public List<SelectOption> getselectCountry(){
        try{
            selectCountry = new List<SelectOption>();
            List<Region_HDS__c> listCountry = [
                                                Select
                                                id,name
                                                from 
                                                Region_HDS__c
                                                where
                                                Region_Type_HDS__c = 'Country'
                                                ORDER BY
                                                Name
                                                ];
            //adding to SelectOption
            for(Region_HDS__c r: listCountry){
                selectCountry.add(new SelectOption(r.name,r.name));
            }
            return selectCountry;
        }               
        catch(Exception e){
            return null;
        }
    }

    //dynamic query on Account with where clause
    public dealRegistrationJSON_hds fakeresponse(){

        //adding the sObject and where clauses 
        try{ 
                string fakeresponse= '{  '+
                ' '+
                ' "listOfCustomers":[  '+
                '{    '+
                '"sCustomerName":"TEST Data System",'+
                '"sCustomerStreetAddress":"123",'+
                '"sCustomerCity" : "san jose",'+
                '"sCustomerState" :"California",'+
                '"sCustomerCountry" : "UnitedStates",'+
                '"sCustomerPostalCode": "12345",'+
                '"sCustomerSiteId": "Account Manager",'+
                '"sCustomerRowId": "1234567" '+
                '}, '+
                '{  '+
                '"sCustomerName":"Test Data System",'+
                '"sCustomerStreetAddress":"123",'+
                '"sCustomerCity" : "san jose",'+
                '"sCustomerState" :"California",'+
                '"sCustomerCountry" : "UnitedStates",'+
                '"sCustomerPostalCode": "12312",'+
                '"sCustomerSiteId": "Account Manager",'+
                '"sCustomerRowId": "1234567" '+
                ' }'+
                ']'+
                '}'+
                '';

            dealRegCust = (dealRegistrationJSON_hds)JSON.deserializeStrict(fakeresponse,dealRegistrationJSON_hds.Class);
            system.debug('>>>>>>>>>' + dealRegCust.listOfCustomers);
            return dealRegCust;   
            }
    catch(Exception e){
                HDS_LoggingException.createExceptionWithoutFuture('DealRegistrationNewEditExtension_HDS/listsObjects' , e.getTypeName() , e.getMessage() , e.getLineNumber() , 
                'Deal Registration' , 'DealRegistrationNewEditExtension');
                return null;
            }
    }

      //Search
    public PageReference searchRecords(){
        try{

            system.debug('json serialize ' + json.serializePretty(oCustomerSearch));
            prospectDisableFlag = false;
            fakeresponse();
        //  customerSearchResults = 
            if(dealRegCust.listOfCustomers == null){  
                check = True;
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'System is down right now. Please try again later'));
                return null;
            }
            else{
                if(dealRegCust.listOfCustomers.isEmpty()){
                    check = True;
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No results found based on your search criteria'));
                }
                return null;
            }
        }
        catch(Exception e){
                HDS_LoggingException.createExceptionWithoutFuture('DealRegistrationNewEditExtension_HDS/searchRecords' , e.getTypeName() , e.getMessage() , e.getLineNumber() , 
                'Deal Registration' , 'DealRegistrationNewEditExtension');
        }
        return null;
     }


}
  • 3
    You should show some of your code. At this moment it is not completely clear what is the problem. Generally you have to implement some callback javascript function in your parent page that gets the parameter from the lookup and process it. – Sergej Utko Jun 1 '15 at 8:12
1
+50

Your controller for this needs to also return the ExternalId when it gets records with which to populate your Parent Page. You can add this field to the Parent as a hidden field for convenience to make it easier for you with the update from the child window and then to the primary SF database. You'll want to have getters and setters that include it so it can be exchanged as it's updated from the child window to the parent page and related controllers.

 custom Lookup ( child Window) 
       Name  column1   column1 ExternalId(Hidden)
        xyz    ----     ----    ExternalId1 
        abc    ----     ----    ExternalId2 

 Parent Window
        Name  column1 ExternalId(Hidden)   
        xyz    ----         ----        
        abc    ----         ----        

What the external system is doing is no different than what we do in the SF UI where we display the AccountName whenever we have a lookup to an Account which is always to the AccountId. Data from an external system is linked to a SF database by matching it using an externalId which is linked with the SF Object's Id.

Edit

From looking at the code you've posted, it appears to me that you need to modify the JS function below to also get the ExternalID and populate it to the Parent Page.

function fillIn(name) {
     var winMain=window.opener;
      if (null==winMain){
            winMain=window.parent.opener;
        }
      var ele=winMain.document.getElementById('{!$CurrentPage.parameters.namefield}');
      ele.value=name;
      CloseWindow();
   }

In addition to adding the ExternalID field to your popup window as an element you can read, you'll also need to add the ExternalID field to your Parent Page code so you can send the data to it from your popup for use as a reference when you save the record you're working on.

  • Thanks crmprogdev. what I understand here , create a hidden column on child window and hidden field(getter,setter) on parent to save the external Id. I don't understand if user clicks on xyz ( child window) the how to get the value of ExternalId1. Should I use jquery to get row data ? Can I do it with apex or Vf.. please suggest the best way to get last column value ( externalId1) when user click on first column of row ( xyz).. Thanks again. – amidstCloud Jun 1 '15 at 21:15
  • If you're comfortable with jQuery, using jQuery to get the row data would be one approach that could be made to work. Unless your child window is linked to your controller, you wouldn't be able to do it using apex. You need some kind of callback JS or jQuery function from your parent window. See @mastOr comment below your question. – crmprogdev Jun 1 '15 at 21:50
  • Yeah . Child Window has a controller. if someone clicks row column , then how can pass the row data to controller ? I can't go with wrapper class and have a check box or radio... please suggest on how to get the externalId1 in the controller if end user clicks on name column (xyz) .... – amidstCloud Jun 1 '15 at 21:55
  • If you post your code, I and others can be more helpful to you. I've already conveyed the concept of what needs to happen. onclick, gets the fields in the row and passes them back to your other page using a JS function. If you're using the same controller, you could presumably pass them through it by creating a method instead of using pure JS/jQ. All depends on how you open and close your child window. Post code if you need people to give you more. – crmprogdev Jun 1 '15 at 22:13
  • I have added the code of the child window... On click of search button , SearchRecords called . I have created a fake response as integration is not in place.. . Now when End user clicks on the Name.. I have called a javascript function and it assign the selected text to parent window element Id.. – amidstCloud Jun 1 '15 at 22:24

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.