<apex:page id="employeeLookupPage" standardController="Employee__c" extensions="employeeMultiSelectLookupController" showHeader="false">
<script type="text/javascript">
function closeAndPassParams(valueTosend){
alert('inside function');
alert(valueTosend);
var parent = window.opener.document;
alert(parent);
var targetField = parent.getElementById('{!$CurrentPage.parameters.namefield}');
alert(targetField);
targetField.value = valueTosend;
self.close();
}
</script>
<apex:form id="EmployeeForm">
<apex:pageBlock title="Employee List" id="employeeList">
<apex:pageBlockSection id="Section" showheader="false" columns="1">
<!--apex:pageblocksectionitem id="SectionItem" >
<apex:outputLabel value="First Name or Last Name Search" for="searchStringPanel" style="font-weight:Bold;padding-right:10px;" />
<apex:outputPanel id="searchStringPanel"-->
<apex:inputText id="srchString" value="{!searchString}"/>
<apex:commandButton title="Go!" value="Go!" reRender="employeePanel" action="{!search}"/>
<!--/apex:outputPanel>
</apex:pageblocksectionitem-->
</apex:pageBlockSection>
<apex:outputPanel id="employeePanel">
<apex:pageBlock id="employeeBlock">
<apex:inputHidden value="{!allSelectedEmpIds}" id="targetId" />
<apex:inputHidden value="{!empName}" id="namefield" />
<apex:pageBlockTable value="{!employeeList}" var="e" id="tblResults">
<apex:inputHidden value="{!e.employee.Id}" id="namefield" />
<apex:column id="selected">
<apex:inputCheckbox value="{!e.isSelected}" id="check" >
</apex:inputCheckbox>
</apex:column>
<apex:column >
<apex:facet name="header">First Name</apex:facet>
<apex:outputText value="{!e.employee.First_Name__c}" id="fname" />
</apex:column>
<apex:column headerValue="Last Name">
<apex:outputText value="{!e.employee.Last_Name__c}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:outputText value="{!e.employee.Email__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
<apex:pageBlockButtons location="bottom">
<div align="Right" draggable="false">
<apex:commandButton value="Ok" id="selectEmp" action="{!processSelected}">
<apex:actionSupport event="onclick" reRender="none" onComplete="closeAndPassParams('{!empName}');" />
</apex:commandButton>
<apex:commandButton value="Cancel" onclick="window.top.close()" />
</div>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
--Lookup page end--- ---Main Page Start--
var popupLookup=null;
var textempId;
var textempNames;
function openEmpLookup(empNames)
{
var url="/apex/employeeLookupPage?namefield=" + empNames;
popupLookup=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
return false;
}
---Main Page end---
--Lookup Controller---
public with sharing class employeeMultiSelectLookupController
{
public List employeeList {get;set;}
public String allSelectedEmpIds{get;set;}
public String empName{get;set;}
public boolean canLookup {get;set;}
public String searchString{get;set;}
private final Opportunity opp;
String soql;
public class employeeWrapper{
public boolean isSelected{get;set;}
public Employee__c employee {get;set;}
public employeeWrapper(Employee__c e){
employee = e;
isSelected = false;
}
}
public employeeMultiSelectLookupController(ApexPages.StandardController contrl){
this.empName = 'abc';
}
public void search() {
getEmployees();
}
public List<employeeWrapper> getEmployees(){
/* if(employeeList == null){*/
if(searchString != null){
soql = 'SELECT Id,Email__c,First_Name__c,Last_Name__c,FullName__c FROM Employee__c ' + 'WHERE FullName__c LIKE \'%'+searchString+'%\' order by FullName__c';
}else{
soql = 'SELECT Id,Email__c,First_Name__c,Last_Name__c,FullName__c FROM Employee__c';
}
employeeList = new List<employeeWrapper>();
for(Employee__c emp: Database.query(soql)){
employeeList.add(new employeeWrapper(emp));
}
// }
return employeeList;
}
public String processSelected(){
//PageReference np;
allSelectedEmpIds = '';
empName = '';
for (employeeWrapper eEmp: employeeList) {
System.debug('checkbox selected'+ eEmp.isSelected);
if(eEmp.isSelected){
allSelectedEmpIds += ';'+eEmp.employee.Id;
empName += ';'+eEmp.employee.FullName__c;
}
}
return empName;
}
public PageReference cancel(){
return null;
}
}
--Main Controller--
Public Ext2{
public String emailToList {get;set;}
private final Opportunity opp {get;set;}
public String selectedEmpIds{get;set;}
public Ext2(ApexPages.StandardController standardController) {
this.opp = (Opportunity)standardController.getRecord();
}
}
I have a requirement wherein users should have the ability to associate email recipients(both salesforce and non salesforce users) and upload a document to 'Notes and Attachment' related list. I had a created a custom object which holds both salesforce and non salesforce users. I was able to achieve the custom lookup following blogs from
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
https://bobbuzzard.blogspot.in/2010/09/visualforce-lookup.html#comment-form
I am stuck at the point where I wanted to pass the selected record Id's from lookup page to the main page(screenshot 1) on the click of the 'OK' button of the lookup page. And also need to close the pop up. Any thoughts?
javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)"