I have a pre-defined case team called Specialists that I want to dynamically add via code a user named Fred Fubar.

How do I do this?

1 Answer 1


Some key points

  • A predefined case team is defined by the object CaseTeamTemplate (reference)

  • The relevant object to construct is CaseTeamTemplateMember (reference). This is a junction record between a User and the CaseTeamTemplate for a given role.

So, the Apex would look like this

User u = [SELECT Id, Name from User WHERE Name = 'Fred Fubar'][0];
CaseTeamTemplate ctt = [SELECT Id, Name FROM CaseTeamTemplate WHERE Name = 'Specialists'][0];
CaseTeamRole ctr = [SELECT Id, Name FROM CaseTeamRole WHERE Name = 'IT Specialist'][0];

insert new CaseTeamTemplateMember(MemberId = u.Id, 
                                  TeamTemplateId = ctt.Id, 
                                  TeamRoleId = ctr.Id );

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .