0

I want to show selected user records details into the custom event vf page and users will Assigned To for event.enter image description here

Custom task VF Page:

<apex:page standardController="Task" extensions="TaskVFPageExtension" >
    <apex:form title="New Task" >
        <apex:sectionHeader title="Task" subtitle="New Task"/>
        <apex:pageBlock title="Task Edit" mode="edit" id="IdPBTask">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" />                  
                <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
            </apex:pageBlockButtons>
            <apex:PageBlockSection title="Task Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Assigned To</apex:outputLabel>
                    <a href="#" id="IduserLookup" onclick="openLookupPopup();" tabindex="2" title="Assigned To Lookup (New Window)" style="text-decoration: none;">
                        <img src="/s.gif" alt="Assigned To Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Assigned To Lookup (New Window)"/>
                    </a>
                    <!--apex:inputField value="{!newTask.OwnerId}"/-->
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Related To</apex:outputLabel>
                    <apex:inputField value="{!newTask.WhatId}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Subject</apex:outputLabel>
                    <apex:inputField value="{!newTask.Subject}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Name</apex:outputLabel>
                    <apex:inputField value="{!newTask.WhoId}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Type</apex:outputLabel>
                    <apex:inputField value="{!newTask.Type}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Due Date</apex:outputLabel>
                    <apex:inputField value="{!newTask.ActivityDate}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Comments</apex:outputLabel>
                    <apex:inputField value="{!newTask.Description}" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Additional Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Status</apex:outputLabel>
                    <apex:inputField value="{!newTask.Status}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Phone</apex:outputLabel>                    
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Priority</apex:outputLabel>
                    <apex:inputField value="{!newTask.Priority}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Email</apex:outputLabel>                    
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Recurrence" columns="1">            
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Create Recurring Series of Tasks</apex:outputLabel>
                    <apex:inputCheckbox value="{!IsRecurringTask}">
                        <apex:actionSupport event="onchange" reRender="IdPBTask" status="IdStatus"/>
                    </apex:inputCheckbox>
                </apex:pageBlockSectionItem>
                <apex:outputPanel id="IdOPRecurringSeries" rendered="{!if(IsRecurringTask==true,true,false)}">
                    Hi
                </apex:outputPanel>
            </apex:PageBlockSection>
            <apex:pageBlockSection title="Reminder">
                <apex:pageBlockSectionItem >
                    <apex:inputCheckbox label="Reminder" value="{!newTask.IsReminderSet}"/>
                    <apex:inputField value="{!newTask.ReminderDateTime}"/>
                </apex:pageBlockSectionItem>    
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <apex:relatedList id="noteslist" list="NotesAndAttachments"/>
<script> 
function openLookupPopup(){ 
var win = window.open("/apex/UserTaskLookupVF", "MyWinName", "height=500,width=700");

// evaluate the return variable from window.open
if (win == null || typeof(win)=='undefined') {
  alert("The pop-up blocker stopped the window form displaying."); 
}
}
</script> 
</apex:page>

apex Code :

public with sharing class TaskVFPageExtension {

    public Boolean IsRecurringTask {get;set;}
    public Task newTask {get;set;}
    public String userNameList {get;set;}
    public String    userNameListHidden {get;set;}
    public Map<Id,String> selectedUsersMap {get;set;}

    public TaskVFPageExtension(ApexPages.StandardController controller) {

    }

}

custom User Lookup VF page :

<apex:page controller="UserTaskLookupAC" showHeader="false" sidebar="false" standardStylesheets="true">
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh(){
    window.opener.location.href="/{!$CurrentPage.parameters.id}";
    window.top.close();
}
</script>
<apex:form id="IdFrm">        
    <apex:outputPanel styleClass="tabHeader" layout="block" style="height:55px;margin-top:10px;">        
        <apex:outputPanel styleClass="customIcon" style="padding: 17px 17px 0 17px;">
        </apex:outputPanel>
        <h1>Lookup</h1>        
    </apex:outputPanel>
    <apex:tabPanel switchType="client" selectedTab="name1" id="theTabPanel" activeTabClass="activeTab" inactiveTabClass="inactiveTab" tabClass="customtab">
        <apex:tab label="Single User" name="name1" id="tabOne" styleClass="customTabStyle">
            <apex:outputPanel layout="block" style="margin-bottom:50px;">                
                <apex:inputText value="{!whereClause}" style=" margin: 10px;" html-placeholder="Search..." />
                <apex:commandButton action="{!go}" value="GO!" rerender="IdAvailableMember" reRender="IdPBSUResult"/>
            </apex:outputPanel>
            <apex:outputLabel value="Search Results" styleClass="srch" />
            <apex:pageBlock id="IdPBSUResult">                
                <apex:pageBlockTable value="{!userList}" var="u" rows="5">
                    <apex:column headerValue="Full Name" >
                        <apex:facet name="Header"><apex:outputLabel >Full Name</apex:outputLabel></apex:facet>
                        <apex:commandLink value="{!u.Name}"/>
                    </apex:column>
                    <apex:column headerValue="Role">
                        <apex:facet name="Header"></apex:facet>                        
                        <apex:commandLink value="{!u.UserRoleId}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:tab>
        <apex:tab label="Multiple Users" name="name2" id="tabTwo" styleClass="customTabStyle" >
            <apex:outputPanel layout="block">
                <apex:outPutLabel value="Search : "/>
                <apex:selectList id="IdGroupPickList" value="{!groupSelectPickListValue}" multiselect="false" size="1" >
                    <apex:selectOptions value="{!GroupSelectPickListOption}"/>
                    <apex:actionSupport event="onchange" action="{!searchSelectOption}"  reRender="IdOPResult" status="IdStatus"/>
                </apex:selectList>
                <apex:outPutLabel value="for: "/>
                <apex:inputText value="{!whereClause}" style=" margin: 10px;"/>
                <apex:commandButton action="{!find}" value="Find" rerender="IdAvailableMember"/>
            </apex:outputPanel>
            <apex:outputPanel id="IdOPResult" layout="block" styleClass="duelingListBox">
                <table class="layout">
                    <tbody>
                        <tr>
                            <td class="selectCell">
                                <apex:outputPanel layout="block" styleClass="selectTitle">
                                    <apex:outputLabel value="Available Members" for="IdOPResult:leftList" />
                                </apex:outputPanel>
                                <apex:selectList id="IdAvailableMember" value="{!availableMemberIds}" multiselect="true" size="14" style="width:100%">
                                    <apex:selectOptions value="{!availableMemberOption}"/>
                                </apex:selectList>
                            </td>
                            <td class="buttonCell">
                                <apex:outputPanel layout="block" styleClass="text">Add</apex:outputPanel>
                                <apex:outputPanel layout="block" styleClass="text">
                                    <apex:commandLink action="{!addMembers}" rerender="IdAvailableMember, IdSelectedMembers" id="IdMBtnRight"> 
                                        <apex:image value="/s.gif" alt="Add" styleClass="rightArrowIcon" title="Add" />
                                    </apex:commandLink>
                                </apex:outputPanel>
                                <apex:outputPanel layout="block" styleClass="text">
                                    <apex:commandLink action="{!removeMembers}" rerender="IdAvailableMember, IdSelectedMembers" id="IdMBtnLeft">
                                        <apex:image value="/s.gif" alt="Remove" styleClass="leftArrowIcon" title="Remove" />
                                    </apex:commandLink>
                                    <apex:outputPanel layout="block" styleClass="duelingText">Remove</apex:outputPanel>
                                </apex:outputPanel>
                            </td>
                            <td class="selectCell">
                                <apex:outputPanel layout="block" styleClass="selectTitle">
                                    <apex:outputLabel value="Selected Members" for="IdOPResult:rightList" />
                                </apex:outputPanel>
                                <apex:selectList id="IdSelectedMembers" value="{!selectedMemberIds}" multiselect="true" size="14" style="width: 200px;">
                                    <apex:selectOptions value="{!selectedMemberOption}"/>
                                </apex:selectList>
                            </td>
                            <td class="buttonCell">
                                <apex:outputPanel layout="block" styleClass="text">Add</apex:outputPanel>
                                <apex:outputPanel layout="block" styleClass="text">
                                    <apex:commandLink action="{!addUsers}" rerender="IdSelectedMembers,IdSelectedUsers" id="IdUBtnRight"> 
                                        <apex:image value="/s.gif" alt="Add" styleClass="rightArrowIcon" title="Add" />
                                    </apex:commandLink>
                                </apex:outputPanel>
                                <apex:outputPanel layout="block" styleClass="text">
                                    <apex:commandLink action="{!removeUsers}" rerender="IdSelectedUsers,IdSelectedMembers" id="IdUBtnLeft">
                                        <apex:image value="/s.gif" alt="Remove" styleClass="leftArrowIcon" title="Remove" />
                                    </apex:commandLink>
                                    <apex:outputPanel layout="block" styleClass="duelingText">Remove</apex:outputPanel>
                                </apex:outputPanel>
                            </td>
                            <td class="selectCell">
                                <apex:outputPanel layout="block" styleClass="selectTitle">
                                    <apex:outputLabel value="Selected Users" for="IdOPResult:rightList" />
                                </apex:outputPanel>
                                <apex:selectList id="IdSelectedUsers" value="{!selectedUserIds}" multiselect="true" size="14" style="width: 200px;">
                                    <apex:selectOptions value="{!selectedUserOption}"/>{!whereClause}
                                </apex:selectList>
                            </td>
                        </tr>
                    </tbody>
                </table>                
            </apex:outputPanel>
            <apex:outputPanel style="margin-left:50%;">
                <apex:commandButton value="Done" action="{!done}" oncomplete="javascript:CloseAndRefresh();"/>
                <apex:commandButton value="Cancel" onclick="javascript:CloseAndRefresh();"/>
            </apex:outputPanel>
        </apex:tab>
    </apex:tabPanel>
</apex:form>    
    <apex:actionStatus id="IdStatus">
        <apex:facet name="start">
            <div class="loadingBG" >
                &nbsp;
            </div>
            <div class="loadingBGP" >
                <div class="loadingDImg" >
                    <img src="/img/loading.gif" style="float: left; margin: 8px;" />
                    <span class="loadingTEXT">Please Wait...</span>
                </div>
                </div>
        </apex:facet>
    </apex:actionStatus>
<style>    
.customTabStyle{
    border-bottom-color:white;
    border-left-color:white;
    border-right-color:white;
    background-color:white;

}
body{
    background: #fff url(/img/alohaSkin/lookup_bg.png) repeat-x;
    padding: 10px;

}
.customIcon{
    background: url(/img/sprites/master.png);
    background-position:0 -1202px;
    width: 32px;
    height: 32px;    
    border:none;    
}
h1{
    font-size: 1.8em;
    color: #333435;
    margin: 8px 0 4px;
}
.customtab{    
    font-size:1.0em;    
    font-weight:bold;
    font-family: Arial,Helvetica,sans-serif;
    //border-radius:20px;}
.activeTab{    
    color:black;
    background-image:none;

}
.inactiveTab{    
    color:black;
    background-image:none;
}
.rich-tabhdr-side-cell{     
    //background-image: url(/img/alohaSkin/subtab_sprite.png);
    //border-top-right-radius: 15px;
}
</style>
</apex:page>

apex code for custom vf lookup

public with sharing class UserTaskLookupAC {

    public PageReference go() {
        return null;
    }   

    public String whereClause { get; set; }
    public String groupSelectPickListValue {get;set;}   
    public List<Group> groupList {get;set;}
    public List<User> userList {get;set;}
    public List<String> availableMemberIds { get; set; }
    public List<String> selectedUserIds { get; set; }
    public List<String> selectedMemberIds { get; set; }
    public List<String> removeUserId {get;set;}    
    public Map<Id,String> avaliableMembersMap {get;set;}
    public Map<Id,String> selectedMembersMap {get;set;}
    public Map<Id,String> selectedUsersMap {get;set;}
    public Static Map<Id,String> staticUsersMap {get;set;}
    public UserTaskLookupAC(){
        groupSelectPickListValue='Group';
        initalization();        
        searchSelectOption();
    }
    public void initalization(){        
        groupList = [SELECT DeveloperName,Id,Name,Type FROM Group where type != 'Role' and type !='RoleAndSubordinates' and type !='RoleAndSubordinatesInternal' and type !='Queue' order by name];
        userList = [SELECT Id,Name,UserRoleId FROM User WHERE IsActive = true ORDER BY Name];
        availableMemberIds = new List<String>();
        selectedUserIds = new List<String>();
        selectedMemberIds = new List<String>();
        avaliableMembersMap = new Map<Id,String>();
        selectedMembersMap = new Map<Id,String>();
        selectedUsersMap = new Map<Id,String>();        
    }

    public List<SelectOption> getGroupSelectPickListOption() {            
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('PR','Portal Roles'));
        options.add(new SelectOption('PRS','Portal Roles & Subordinates'));
        options.add(new SelectOption('Group','Public Groups'));
        options.add(new SelectOption('Roles','Roles'));
        options.add(new SelectOption('RIS','Roles and Internal Subordinates'));
        options.add(new SelectOption('RIPS','Roles, Internal and Portal Subordinates'));
        options.add(new SelectOption('Users','Users'));
        return options;
    }

    public void searchSelectOption(){
        if(groupSelectPickListValue=='Group'){
            avaliableMembersMap.clear();
            for (Group g : groupList) {                
                avaliableMembersMap.put(g.Id, 'Group: '+g.DeveloperName);
            }
        }
        if(groupSelectPickListValue=='Roles'){
            avaliableMembersMap.clear();
            for (UserRole ur: [SELECT Id,Name,ParentRoleId,PortalRole,PortalType FROM UserRole WHERE PortalType = 'None']) {                
                avaliableMembersMap.put(ur.Id, 'Role: '+ur.Name);
            }
        }
        if(groupSelectPickListValue=='RIS'){
            avaliableMembersMap.clear();
            for (UserRole ur : [SELECT Id,Name,ParentRoleId,PortalRole,PortalType FROM UserRole WHERE ParentRoleId != null AND PortalType = 'none' ORDER BY Name]) {                
                avaliableMembersMap.put(ur.Id, 'Roles and Internal Subordinates: '+ur.Name);
            }
        }
        if(groupSelectPickListValue=='RIPS'){
            avaliableMembersMap.clear();
        }
        if(groupSelectPickListValue=='Users'){
            avaliableMembersMap.clear();
            for (User u : userList) {                
                avaliableMembersMap.put(u.Id, 'User: '+u.Name);
            }
        }

    }

    public List<SelectOption> getAvailableMemberOption() {
        List<SelectOption> option = new List<SelectOption>();
        for (Id sId : avaliableMembersMap.keySet()) {
            option.add(new SelectOption(sId, avaliableMembersMap.get(sId)));
        }
        return option;
    }

    public void addMembers() {
        if(groupSelectPickListValue=='Group'){
            if (!availableMemberIds.isEmpty()) {
                for(String uId : availableMemberIds){
                    List<GroupMember> gm = [SELECT UserOrGroupId FROM GroupMember WHERE GroupId =:uId];
                    List<String> group_id  = new  List<String>();
                    for(GroupMember g:gm){
                        group_id.add(g.userorgroupid+'');
                    }
                    List<USER> userList = [SELECT id,name from User where IsActive = true and id in :group_id];            
                    for(User u:userList){
                        selectedMembersMap.put(u.Id,u.name);
                    }
                }
            }
        }
        if(groupSelectPickListValue=='Roles'){
            if (!availableMemberIds.isEmpty()) {
                for(String uId : availableMemberIds){
                    List<USER> userList = [SELECT Id,Name,UserRoleId,UserType FROM User WHERE IsActive = true and UserRoleId =:uId];
                    for(User u:userList){
                        selectedMembersMap.put(u.Id,u.name);
                    }
                }
            }
        }
        if(groupSelectPickListValue=='RIS'){
            if (!availableMemberIds.isEmpty()) {
                for(String uId : availableMemberIds){
                    List<USER> userList = [SELECT Id,Name,UserRoleId,UserType FROM User WHERE IsActive = true and UserRoleId =:uId];
                    for(User u:userList){
                        selectedMembersMap.put(u.Id,u.name);
                    }
                }
            }
        }
        if(groupSelectPickListValue=='Users'){
            if (!availableMemberIds.isEmpty()) {
                for (String uId: availableMemberIds) {
                    selectedMembersMap.put(uId, avaliableMembersMap.get(uId));
                    avaliableMembersMap.remove(uId);
                }
            }
        }
    }
    public List<SelectOption> getSelectedMemberOption() {
        List<SelectOption> option = new List<SelectOption>();
        for (String sId : selectedMembersMap.keySet()) {
            option.add(new SelectOption(sId, selectedMembersMap.get(sId)));
        }
        return option;
    }

    public PageReference find() {
        return null;
    }

    public void removeMembers() {
        selectedMembersMap.clear();
    }

    public List<SelectOption> getSelectedUserOption() {
        List<SelectOption> option = new List<SelectOption>();
        for (String sId : selectedUsersMap.keySet()) {
            option.add(new SelectOption(sId, selectedUsersMap.get(sId)));
        }
        return option;
    }

    public void addUsers() {
        if (!selectedMemberIds.isEmpty()) {
            for (String sId : selectedMemberIds) {
                selectedUsersMap.put(sId,selectedMembersMap.get(sId));
                selectedMembersMap.remove(sId);
            }
        }
    }
    public void removeUsers() {
        if (!selectedUserIds.isEmpty()) {
            for (String sId : selectedUserIds) {
                selectedMembersMap.put(sId, selectedUsersMap.get(sId));
                selectedUsersMap.remove(sId);
            }
        }
    }
    public Static Map<Id,String> taskLookupUserMap(Map<Id,String> mp){        
        return mp;
    }
    public PageReference done() {
        staticUsersMap=selectedUsersMap;
        return null;
    }

}
  • You'll need to add your code to get a decent answer, otherwise impossible to judge what is going wrong.. – Guy Clairbois Sep 23 '16 at 7:07
  • Sure... :) @Guy – GmDeepakChounan21 Sep 23 '16 at 7:22
  • 1
    What is your question – Eric Sep 23 '16 at 7:33
  • Hi @Guy, i have add all the code. Thank you so much for your support... :) – GmDeepakChounan21 Sep 23 '16 at 7:35
  • Hi @Eric, i have create custom event vf page with custom user lookup vf page. i want to create event for Group. for exp. i have 4 user into GroupA but i want to create a event for only 2 user. i am trying to fetching user id or name but not success. Thank you – GmDeepakChounan21 Sep 23 '16 at 7:48
2

You need to handle the saving of the selected values in the popup controller (in the done() method).

In order to do this, you need the Id of the Event that you started from. In order to pass that to the popup, use e.g. a URL parameter (see this page for an example)

The in the done() method, add some DML to insert the selected users to the Event, and forward the user to a fresh Event detail page, so that the new Event participant are shown on the screen (the screen will not automatically be refreshed when just closing the popup)

  • Hi @Guy, i have already try this code. but we get one record at the same time. but in this lookup we have to pass list of record. Is it possible to get list from this code. – GmDeepakChounan21 Sep 23 '16 at 12:40
  • What I mean is only use the first part of that example (to pass the Event Id to the popup controller). Then in the popup controller, just save the Event attendees with a DML insert. Then reload the Event page, and it will show the Event attendees. So you don't write back the selected id's to the original page, but instead refresh the page after inserting the attendees in the database. – Guy Clairbois Sep 23 '16 at 14:42

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.