I have a page where users are asked to enter a related Case Team Member. The case team member can be a User or Contact but I want to limit it to User only. How can I? Is it possible to default the dropdown to User? Thanks Apex Class

public class CasewithCaseTeamExtension {

private ApexPages.StandardController sc;

public CaseTeamMember CTM {get; set;}
public List<CaseTeamMember> CTMS {get; set;}

public String selectedCaseTeamMember {get; set;}   

public string Username {
    get {
            return [
                    select Name
                    from User
                    where Id = :Userinfo.getUserId()


public CasewithCaseTeamExtension (ApexPages.StandardController StandardController) {

    //Store a reference to the standard controller
    sc = standardController;

    //create a new sprint instance to collect user input
    CTM = new CaseTeamMember();

    //create a new list to store the sprints added by the user
    CTMS = new List<CaseTeamMember>();


public PageReference ToPage2() {


        //Save code will go here

    return Page.CaseCreateCTM2;

public PageReference SaveCTM() {

    Case Case1 = (Case)sc.GetRecord();
    CaseTeamRole CTRole = [select id from CaseTeamRole where name =:'KCG'];
    CTM.ParentId = Case1.Id;
    CTM.TeamRoleId = CTRole.Id;
    insert CTM;

    CTM = new CaseTeamMember();

    return null;


public PageReference SaveAndFinish() {

    Case Case1 = (Case)sc.GetRecord();
    CaseTeamRole CTRole = [select id from CaseTeamRole where name =:'Internal Support[![enter image description here][1]][1]'];
    CTM.ParentId = Case1.Id;
    CTM.TeamRoleId = CTRole.Id;

    CTM = new CaseTeamMember();

    PageReference redirecturl = new PageReference('/'+Case1.id);
    return redirecturl;

public PageReference FinishEntry() {
  Case Case1 = (Case)sc.GetRecord();

    PageReference redirecturl = new PageReference('/'+Case1.id);
    return redirecturl;



VF page code:

<apex:page standardController="Case" extensions="CasewithCaseTeamExtension" >

    <apex:form >
        <apex:pageBlock title="Add Interested Parties to the Case Team Members List Here">
            Case Team Members will be included in email notifications about the Case.   
            <apex:pageBlockButtons location="bottom">
                     <apex:commandButton action="{!SaveCTM}" value="Add Person to Case" />
                   <apex:commandButton action="{!FinishEntry}" value="Complete Case Entry"  immediate="true"/>

            <apex:pageBlockSection columns="1">
              <apex:inputField value="{!ctm.MemberId}" label="Name" />


             <apex:pageBlock title="Added">
                <apex:pageBlockTable value="{!CTMS}" var="s">
                    <apex:column value="{!s.MemberId}"/>



enter image description here

  • is this a VF page that asks for the related CTM? If yes, please post it and the associated controller (relevant excerpts only) – cropredy Feb 20 '16 at 23:33
  • uploaded. the circled part is what I want to default to User, not Contact – jaw999 Feb 22 '16 at 13:03

I can see three options

Option 1 - jQuery

Here, you remove Contacts from the dropdown list in the SFDC-generated input control. This is SFDC hacking and subject to breaking in the future.

Option 2 - Proxy object in controller

Here, you find some SObject with a lookup field to User (Like User.Manager) and you bind the VF page inputField to an instance of that SObject in your controller. Think of this as a proxy object.

Wen you get to saveCTM(), you copy the value from that proxy object to ctm.memberId and continue with the save logic.

Here is an example proxy and corresponding VF page that you can adapt to your specific use case

public with sharing class FooController {
    public User proxyU  { // provides User lookup i/o behavior to VF page
        get {             // as User.managerId is a lookup to User
            if (this.proxyU == null)
                this.proxyU = new User();
            return this.proxyU; 

    public PageReference myAction() {
        Account a = new Account(  // copy managerId from proxy to our sobject field
                     ownerId = proxyU.managerId, name='proxyExample'); 
        insert a;
        PageReference resPg = new PageReference('/'+a.id);
        return resPg;

<apex:page controller="FooController">
        <apex:outputLabel value="Select user using lookup"/>
        <!-- SFDC generates a component that does lookup only on Users --> 
        <apex:inputField value="{!proxyU.managerId}"/> 
        <apex:commandButton value="Go" action="{!myAction}"/>

Option 3 - a custom lookup popup

There are several examples of this available; to cite a few...

Jeff Douglas

Bob Buzzard

Terence Yuven Viban


Option 1 is potentially fragile but introduces no new Apex code

Option 2 is easy, I use this technique, for example, to create input boxes to exploit the SFDC date picker when the inputs would not normally be bound to any sobject (like letting the user pick a start/end date for a dynamic soql query where clause)

Option 3 gives you the most flexibility as you can customize the list of Users to be only relevant ones

  • I like the proxy idea. are the documented examples you can share? – jaw999 Feb 22 '16 at 19:16
  • @jaw999 - added a snippet for you - adapt as needed to your CTM use case – cropredy Feb 22 '16 at 21:54

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.