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
sushmaiyer2@gmail.comsushmaiyer2@gmail.com 

Not able to select a value from custom lookup window

 

 

Hi All,

 

I am Not able to select a value from custom lookup window after clicking "insert selected" Button.

 

My VF Page :-

 

<apex:page controller="CustomLookupWindowController" showHeader="false" sidebar="false">
    
    <STYLE type="text/css">
        .pageTitleIcon {
            background-image: url("/img/sprites/master.png");
            background-position: 0 -1202px;
            height: 32px;
            width: 32px;
        }
        
        body {
            font-family: Arial,Helvetica,sans-serif;
            background: url("/img/alohaSkin/lookup_bg.png") repeat-x scroll 0 0 #FFFFFF;
            margin: 0 10px;         
        }
        
        .bPageTitle h1 {
            color: #333435;
            font-size: 1.8em;
            margin: 8px 0 4px;
        }
        
        .bPageTitle h1, .bPageTitle h2 {
            display: block;
        }
        
        .ValueLabel {
            color: #4A4A56;
            font-size: 0.9em;
            margin: 0 5px 0 0;
        }       
                
    </STYLE>

    <script type="text/javascript">
        function setValueOnParentWindowAndClose(ValueToSet) {
            // update the input on the caller
            window.opener.document.getElementById('{!InputDOMName}').value = ValueToSet;
            // fire the on change event in our input so the caller knows it was updated
            window.opener.document.getElementById('{!InputDOMName}').onchange();
            self.close();
        }       
    </script>

    <body onBlur='javascript&colon;window.close();'>      
        <div class="bPageTitle">
            <img class="pageTitleIcon" title="" alt="" src="/s.gif" />
            <h1>Lookup</h1>
        </div>
        
        <apex:outputPanel id="TextSearchResultsOP" rendered="{!RenderTextSearch}" >
            <apex:form >
                                
                <div class="pbBody">
                    <strong>Search</strong>&nbsp;&nbsp;
                    <apex:inputText value="{!TextSearchInput}" id="TextSearchInput" />
                    &nbsp;&nbsp;
                    <apex:CommandButton value="Go!" action="{!TextSearch}" />
                
                    <br/>
                    
                </div>
                
                <p style="padding-left: 30px;">
                    <h2>You can use "*" as a wildcard next to other characters to improve your search results.</h2>
                </p>
                
                <br/><br/><br/>
                                
                <apex:PageBlock id="TextSearchResultsPB" >              
                    
                    <apex:pageBlockTable value="{!TextOptionsList}" var="T" >
                            <apex:column value="{!T}" onclick="setValueOnParentWindowAndClose('{!JSENCODE(T)}');">              
                                <apex:facet name="header">Name</apex:facet>                                 
                            </apex:column>                  
                    </apex:pageBlockTable>
                    
                </apex:PageBlock>
                
            </apex:form>        
        </apex:outputPanel>
                
        <apex:outputPanel id="ListSearchResultsOP" rendered="{!RenderListSearch}">
        
            <div class="pbBody">
                <h2>Select the picklist values to add below.</h2>
            </div>

            <apex:form >    
                            
                <apex:outputPanel id="ListSearchResultsOP" >
                    
                    <center><apex:CommandButton value="Insert Selected" action="{!BuildSelectedString}" oncomplete="setValueOnParentWindowAndClose('{!JSENCODE(SelectedString)}');" /></center>
                    
                    <apex:PageBlock id="ListSearchResultsPB" >              
                    
                        <apex:pageBlockTable value="{!ListModeOptionsList}" var="L">
    
                            <apex:column style="width: 1%;">                
                                <apex:facet name="header">
                                    <apex:inputCheckbox value="{!SelectAllList}">
                                        <apex:actionSupport event="onclick" action="{!SetCurrentSelectedListWrapperSelected}" rerender="ListSearchResultsPB" immediate="true"/>
                                    </apex:inputCheckbox>
                                </apex:facet>   
                                <apex:inputCheckbox value="{!L.Selected}"/>
                            </apex:column>
    
                            <apex:column styleclass="ValueLabel">
                                <apex:facet name="header">Value</apex:facet>
                                {!L.Value}
                            </apex:column>
    
                        </apex:pageBlockTable>
                        
                    </apex:PageBlock>                                       

                    <center><apex:CommandButton value="Insert Selected" action="{!BuildSelectedString}" oncomplete="setValueOnParentWindowAndClose('{!JSENCODE(SelectedString)}');" /></center>
                                                        
                </apex:outputPanel>
                                                            
            </apex:form>        
        </apex:outputPanel>
    </body>
</apex:page>

 

 

My Controller :-

 

public with sharing class CustomLookupWindowController {
    
    public boolean RenderListSearch {get; set;}
    public boolean RenderTextSearch {get; set;}
    public boolean SelectAllList {get; set;}
    
    public List<SelectedListWrapper> ListModeOptionsList  {
        get {
            if (ListModeOptionsList == null) ListModeOptionsList = new List<SelectedListWrapper>();
            return ListModeOptionsList;
        }
        set;
    }
        
    public string TextSearchInput {get; set;}
    
    public List<String> TextOptionsList  {
        get {
            if (TextOptionsList == null) TextOptionsList = new List<String>();
            return TextOptionsList;
        }
        set;
    }
        
    public string SelectedString {get; set;}
        
    public CustomLookupWindowController() {
        
        RenderListSearch = false;
        RenderTextSearch = false;
        SelectAllList = false;
        TextSearchInput = '';
                
        string CurrentObjectName = getObjectName();
        string CurrentFieldName = getFieldName();
        string CurrentFormInputDOMName = getFormDOMName();
        
        if (CurrentObjectName != null) {                        
            
            Type CurrentType = Type.forName(CurrentObjectName);
                        
            object CurrentObject = CurrentType.newInstance();
            
            if (CurrentObject != null) {
                
                Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
                
                Schema.SObjectType CurrentSObjectType = gd.get(CurrentObjectName);
                
                if (CurrentSObjectType != null) {
                    
                    Map<String, Schema.SObjectField> FieldsMap = CurrentSObjectType.getDescribe().fields.getMap();
                                        
                    Schema.SObjectField CurrentField = FieldsMap.get(CurrentFieldName);
                                        
                    Schema.DisplayType CurrentFieldType = CurrentField.getDescribe().getType();
                    
                    
                    if (CurrentFieldType == Schema.Displaytype.PickList || CurrentFieldType == Schema.Displaytype.MultiPickList) {
                      
                        PopulateListModeOptionsList(CurrentField);
                        RenderListSearch = true;
                    } else {
                        
                        RenderTextSearch = true;
                    }
                
                }
                
            }
            
        }
        
    }
    
        public void TextSearch() {
        string ObjectName = string.escapeSingleQuotes(getObjectName());
        
        string SOQLQueryString = 'SELECT ID, NAME FROM ' + ObjectName + ' WHERE NAME LIKE \'%' + TextSearchInput + '%\'';
        
        List<sObject> SearchResults = Database.query(SOQLQueryString);
        
        TextOptionsList.clear();
        
        for (sObject R: SearchResults) {
            TextOptionsList.add(string.valueof(R.get('Name')));
        }
                
    }
    
    private void PopulateListModeOptionsList(Schema.SObjectField CurrentField) {
        
        List <Schema.PicklistEntry> CurrentListValues = CurrentField.getDescribe().getPicklistValues();
        List <String> OptionsList = new List<String>();
        
        for (Schema.PicklistEntry P : CurrentListValues) {
            OptionsList.add(P.getValue());
        }

        OptionsList.sort();

        ListModeOptionsList.clear();
        
        for (String V: OptionsList) {
            SelectedListWrapper CurrentSelectedListWrapper = new SelectedListWrapper();
            CurrentSelectedListWrapper.Value = V;
            CurrentSelectedListWrapper.Selected = false;
            ListModeOptionsList.add(CurrentSelectedListWrapper);
        }
        
    }
        
    public void SetCurrentSelectedListWrapperSelected() {
        
        SelectAllList = !SelectAllList;
        
        for (SelectedListWrapper S: ListModeOptionsList) {
            S.Selected = SelectAllList;
        }    
    }
    
    public void BuildSelectedString() {
        
        SelectedString = '';
                
        for (SelectedListWrapper S: ListModeOptionsList) {
            if (S.Selected == true) {               
                if(S.Value.containsAny(',') == true) {
                    
                    SelectedString += '\"' + S.Value + '\"' + ', ';     
                } else {
                    
                    SelectedString += S.value + ', ';
                }
            }
        }
        
        if (SelectedString.endsWith(',')) SelectedString = SelectedString.removeEnd(',');
            
    }
    
    public string getFormDOMName() {
        return System.currentPageReference().getParameters().get('form');
    }
    
    public string getInputDOMName() {
        return System.currentPageReference().getParameters().get('input');
    }
    
    public string getObjectName() {
        return System.currentPageReference().getParameters().get('object');
    }
    
    public string getFieldName() {
        return System.currentPageReference().getParameters().get('field');
    }
    
    private class SelectedListWrapper  {
    
    public boolean Selected {get; set;}
    
    public string Value {get; set;}
    }
      
 
}