2

I would like to know whether it is possible to implement a custom lookup (not a lookup relationship)where I can do a multiselect of users.

This selection of multiple users will result in their emails concatenated and stored in a field.

For example while creating custom views we can select multiple "Type"

enter image description here

After selecting the picklist values the field stores concatenated value of all the selected ones like below.

enter image description here

Similarly I would like to know whether I can create a multiselect lookup where I can select multiple users and after selection their emails should be concatenated and stored in a field.

  • where would the lookup need to be located? In a standard page or VF page? – Guy Oct 20 '14 at 12:37
  • @guy : visual force page – Varun Oct 20 '14 at 16:15
5

Sure this can be quite a straightforward VisualForce page addition. I will provide some leads below which should be enough to get you to a solution. Everything should be added to your existing page / controller.

In order to have a popup-effect but keep your current state (after selecting the users, you want to return the result to the page at which you're currently at without too much effort), you can use some css styling.

<apex:outputPanel rendered="{!showPopup}" >
    <apex:outputPanel styleClass="customPopup" layout="block" >
        <!-- put your popup contents here -->
        <!-- will be e.g. a pageBlockTable with the Users (incl checkbox to select) and a 'save' and 'cancel' button -->
    </apex:outputPanel>
</apex:outputPanel>

<style type="text/css">      
 .customPopup{            
      background-color: white; 
      border-style: solid; 
      border-width: 1px;
      left: 50%;           
      padding:10px;           
      position: absolute;           
      z-index: 9;           
       /* These are the 3 css properties you will need to tweak so the pop             
       up displays in the center of the screen. First set the width. Then set            
       margin-left to negative half of what the width is. You can also add            
       the height property for a fixed size pop up.*/            
      width: 750px;            
      margin-left: -375px;
      top:50px;        
}

Then in the popup, load a list of Users. In order to make them selectable, you could create a wrapper for the Users, adding a Boolean that indicates whether they are selected or not. Upon initializing the page, you can already load the users.

public with sharing class pageController {

public pageController(){
    users = new List<UserWrapper>();

    for(User theUser : [Select Id from User Where Name != null]{
        UserWrapper uw = new UserWrapper();
        uw.u = theUser;
        uw.selected = false;
        users.add(uw);

    }
}

public Boolean showPopup {get;private set}

public List<UserWrapper> users {get;set;}
public class UserWrapper {
    public User u {get;private set;}
    public Boolean selected {get;set;}
}

}

Also add some pageReferences for the save and cancel methods. The save method will contain the logic to go through the list of users, checking whether they are selected or not, and if they are, adding their Email address to a String which you will then write back to the field.

3

The fact you want to store them in a field would in itself be very limiting because of the limit on the number of records you could hold in a field, even if it were a large text area. This type of approach wouldn't be scalable. You'd quickly hit a limit on the number of records you could store. The second problem you'd have is that you want this to be a dynamic search.

That having been said, I've seen this type of thing done using a junction object to hold the search criteria and a custom "results object" to hold the search results. Its not totally clear to me whether you need to retain these related lists as records or simply refresh them periodically nor how many searches need to be retained. If there's only one, this approach will definitely work very well for you.

For retaining more than one search, keeping each one as a separate record may require you to set up all the different search options ahead of time, then call them as preconfigured searches. I'm not entirely certain on that. I say this because we wound up scrapping this approach to the problem we were trying to solve and only worked with it for a limited time. However, I hope this helps point you to a solution that will work for you.

  • "because of the limit on the number of records you could hold in a field"..it will be just 3-4 emails concatenated with each other separated by comma..i guess 255 char limit should suffice for this particular req – Varun Oct 20 '14 at 16:23
1

Simple answer: you can't.

At least not with a simple lookup field on a page. Unless maybe Salesforce can somehow enable this feature just for you, but I doubt that.

If you want something like that, you will have to write it custom in Visualforce.

  • Can you care to provide a high level pointer as to how this can be done in VF..The page where I want the lookup is a VF page only – Varun Oct 20 '14 at 16: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.