Sub topic 11
Opportunity teams and case teams
This chapter assumes you know org-wide defaults, record ownership, and the role hierarchy. It also assumes you know how the account team grants access, and basic SOQL for the code sections. Here you will see how opportunity teams and case teams open access on one record at a time, how they differ from account teams, and how to inspect them.
What these teams do
An opportunity team is a set of users who work on one opportunity with the owner. A case team is the same idea for a case. Both exist to give extra people access to a single record without changing the owner, the role hierarchy, or a sharing rule.
Teams can only open access. If the org-wide default for Opportunity or Case is Public Read/Write, everyone already has full access, so a team adds nothing. Teams matter when the default is Private or Public Read Only.
Team membership does not grant object permissions. A team member still needs Read on the Opportunity or Case object through a profile or permission set. Without that, the team row is stored but the user cannot see the record.
Enabling the features
Neither feature is on by default. An administrator turns each one on in Setup:
- Opportunity teams: Opportunity Team Settings, then Enable Team Selling.
- Case teams: Support Settings, then Enable Case Teams. Then define case team roles.
Until they are enabled, the team related lists and the team objects are not available.
Opportunity teams
An opportunity team member has three main values:
- The user.
- A team role, such as Sales Engineer or Executive Sponsor. The roles come from a picklist an administrator maintains.
- An access level on the opportunity: Read Only or Read/Write.
The access level is set per member. Two people with the same role can have different access to the same opportunity.
Default opportunity teams
Each user can define a personal default opportunity team. When that user creates an opportunity, or the user adds the default team, the members are copied to the opportunity. The copy is a snapshot. Later changes to the default team do not change opportunities that already exist.
Relationship to the account team
The account team grants access to the account. Each account team member also has an opportunity access level, which controls access to that account's opportunities. An opportunity team is narrower. It applies to one opportunity only.
Use the opportunity team when a person should see a single deal. Use the account team when a person should see every deal on the account.
Case teams
A case team differs from an opportunity team in three ways:
- The access level belongs to the role. An administrator creates case team roles in Setup and sets each role's access to Read Only or Read/Write. Everyone given that role gets that access. To give someone different access, assign a different role.
- Members can be users or contacts. Adding a contact lets an external person be part of the team, depending on your portal or Experience Cloud setup.
- Administrators can define predefined case teams. A predefined case team is a named group of members and roles. An agent applies the whole group to a case in one step.
| Feature | Opportunity team | Case team |
|---|---|---|
| Where access level is set | On each member | On the team role |
| Member types | Users | Users and contacts |
| Reusable groups | Personal default team | Predefined case teams |
| Share object | OpportunityShare | CaseShare |
| Team member object | OpportunityTeamMember | CaseTeamMember |
How team access is stored
Each team member produces a row in the share table for the record. Opportunity team members appear in OpportunityShare and case team members in CaseShare. The row cause is Team. When you remove a member from the team, Salesforce deletes the matching share row.
You can treat the share row as a read-only result. Edit the team, not the share row. Row causes of Team cannot be created directly. The next chapters cover share tables and Apex sharing, where you can create shares with other row causes.
Implicit access to the parent account
Access to an opportunity or case can also give a user limited read access to the parent account. This is implicit sharing. It lets the user see the account name and context for the work they were given, but it does not give the account's other opportunities or cases. Do not rely on it as a way to grant account access. Use the account team for that.
Inspecting teams with SOQL
Query the team member objects to see who is on a team, and the share objects to confirm the resulting access.
SELECT Id, OpportunityId, UserId, TeamMemberRole, OpportunityAccessLevel
FROM OpportunityTeamMember
WHERE OpportunityId = '<opportunity record Id>'SELECT Id, OpportunityId, UserOrGroupId, OpportunityAccessLevel, RowCause
FROM OpportunityShare
WHERE OpportunityId = '<opportunity record Id>'For a case, query CaseTeamMember and CaseShare. CaseTeamMember has ParentId, MemberId, and TeamRoleId. CaseShare uses CaseId, UserOrGroupId, CaseAccessLevel, and RowCause.
SELECT Id, ParentId, MemberId, TeamRoleId
FROM CaseTeamMember
WHERE ParentId = '<case record Id>'If a user appears in the team query but not in the share query, check that the member was saved and that the share rows were recalculated. If the user appears in both, check object permissions next.
Adding members from Apex
You can create team members in code. The following two methods add a member to an opportunity team and to a case team. They use partial-success inserts, so a failure is reported without throwing an exception.
public class TeamMemberService {
public static void addOpportunityMember(Id opportunityId, Id userId) {
OpportunityTeamMember member = new OpportunityTeamMember(
OpportunityId = opportunityId,
UserId = userId,
TeamMemberRole = 'Sales Engineer',
OpportunityAccessLevel = 'Edit'
);
Database.SaveResult result = Database.insert(member, false);
if (!result.isSuccess()) {
System.debug(result.getErrors()[0].getMessage());
}
}
public static void addCaseMember(Id caseId, Id userId, String roleName) {
CaseTeamRole role = [
SELECT Id FROM CaseTeamRole WHERE Name = :roleName LIMIT 1
];
CaseTeamMember member = new CaseTeamMember(
ParentId = caseId,
MemberId = userId,
TeamRoleId = role.Id
);
Database.SaveResult result = Database.insert(member, false);
if (!result.isSuccess()) {
System.debug(result.getErrors()[0].getMessage());
}
}
}The role name Sales Engineer must exist in the team role picklist, and the case role must exist in Setup. If it does not, the opportunity insert fails with a message in getErrors(), and the case query throws a QueryException because no row is returned. The access level values in the API are Read and Edit.
Common problems
- The team member cannot see the record. The usual cause is a missing Read permission on the object. Check the profile and permission sets before you look at sharing.
- The access level on the team is lower than what the user already has. Teams do not reduce access. Ownership, the role hierarchy, and sharing rules can all give more, and the user gets the highest level.
- A default team did not update older opportunities. The default team is copied at creation time. Update existing opportunities separately.
- A case team member has the wrong access. The role controls it, so change the role or the role's access level. Changing a role's access level affects every member who holds that role.
- The team related list is missing. Check that the feature is enabled and that the related list is on the page layout or Lightning record page.
Exercise
A Private-default org has a case team role called Escalation Reviewer with Read Only access. Priya is added to a case with that role, but she still cannot open the case. List two things you would check, and then say what you would change to give her edit access on that case.
Show answer
First, check that Priya's profile or a permission set gives her Read on the Case object, because team access does not grant object permissions. Second, query CaseShare for the case and confirm a row with Priya's Id and RowCause Team exists. To give her edit access, assign her a case team role whose access level is Read/Write, or change the role's access level to Read/Write. Changing the role affects every member with that role, so assigning a different role is the narrower fix.