Multiselect Picklists for User Search and Selection using Apex and Visualforce

9 Dec

Below is a component that will allow you to search and select Users. It was created to mimic the experience of selecting multiple users in the Task creation window. However, it would be easy to change the reference from the User object to almost any other object.

An initial list of selected users can be assigned by passing an Id list in the component attribute aInitialRightList. The list referenced in the aCurrentRightList attribute will be updated anytime entries in the right multiselect picklist change. The aWidth attribute accepts px or %, and it sets the width of the entire component.

I’d like to thank those who posted sample code that helped me with the multiselect picklist component. I borrowed ideas and code from the following:
Custom Multi-Select picklist field in Visualforce
A Multiselect Picklist Visualforce Component

Multi Select Picklist Visualforce Component Example

UserMultiSelectComponent.component

UserMultiSelectComponentController.cls

ExamplePage.page

ExamplePageController.cls

UserMultiSelectComponentControllerTest.cls

Visualforce Help Text and a Popup Tool Tip

21 Oct

Visualforce Field Help Text

The help icon can be added to a Visualforce field within an apex:pageBlockSectionItem. Access the help text using the $ObjectType api. Put it in the helptext attribute of the apex:pageBlockSectionItem.

Easy Hover Tooltip

The following may help if you are not using the apex:pageBlockSectionItem. I’ve used this technique in the past to put help text on an image in a apex:pageBlockTable and on plain text in a page.

Example:

Hover Over Me
your message here


Thanks to www.kollermedia.at/archive/2008/03/24/easy-css-tooltip/ for providing an easy way to add tooltip help. He does it by putting the style on the link tag instead of the div.

March 16, 2014: Here is another tutorial that explains how to do a popup tool tip. Tutsplus – Tooltip

Define and Initialize a Map, List, and Set in Apex

20 Oct

The syntax for defining a list, map, and set collection with initial values sometimes slips my mind. The lack of () throws me off, so this post is to help out my future self.

List Definition

Set Definition

Map Definition

Defining a List of Maps

Defining a Map of Lists

Defining a Map of Maps

Sample logic to retrieve the nested Map’s value

This function accepts Param1 as the key for the outer map. Param2 is the key for the inner map. TheMap is a map that contains a nested map which will be worked with. First, we see if there is a key value in the outer map that matches Param1. When it contains the key, the next statement creates a reference to the inner map in the variable TempMap. TempMap is checked for the value of Param2, and the value is returned when found. Finally, null is returned when there is not a match.

Sort a list of sObjects: quick and dirty -or- elegant

2 Oct

Quick and Dirty

Here is a method that I’ve implemented to sort lists of objects by combinations of fields. I don’t claim that it is pretty, but it has worked for me.

With the help of a method from my other post.

Elegant

Implement the Comparable interface on a sub-class allows a list of the objects to be sorted using a familiar ‘.sort()’ method.

Now that your subclass is setup, you can use the built-in sort method for the instantiated object list.