Sub topic 3
Opportunity Teams, Case Teams, and Record Sharing
Assume you know profiles, permission sets, objects, and basic SOQL. Teams provide record access in addition to object permissions, field-level security, ownership, the role hierarchy, and org-wide defaults.
Opportunity teams and case teams
An opportunity team is a group of users working on one opportunity. Each member has a team role, such as Account Manager, and an access level for the opportunity. An account team works similarly for accounts. Case teams support users who collaborate on individual cases.
Team access is useful when membership changes from record to record. For example, a sales engineer can receive Read access to one opportunity without receiving access to every opportunity owned by the sales department. Enable teams in Setup, then configure team roles and the access levels that members can receive.
flowchart TD
A[User has object permission] --> B[User owns record or gains access]
B --> C[Opportunity or case team]
C --> D[Additional record access]Recalculation and share records
Salesforce recalculates sharing when ownership, role membership, org-wide defaults, sharing rules, or qualifying record fields change. Criteria-based rules can therefore add or remove access after a record update. Large recalculations can take time, so test changes in a sandbox and plan production changes carefully.
Salesforce stores many grants in share objects. A custom object named Invoice__c has an Invoice__Share object. AccessLevel commonly contains Read or Edit. RowCause explains why the row exists, such as Owner, Manual, or a sharing rule.
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'For account teams, inspect the team record:
SELECT Id, AccountId, UserId, TeamMemberRole, AccountAccessLevel
FROM AccountTeamMember
WHERE AccountId = '<account record Id>'Troubleshooting and Apex sharing
Start with object permission and field-level security. Then check ownership, role hierarchy access, teams, sharing rules, manual shares, and the target user's group membership. Inspect the relevant share object to find the reason.
Use Apex sharing when the access decision is dynamic and cannot be expressed safely with a rule or team. Set RowCause explicitly and handle DML errors.
public static void shareInvoice(Id invoiceId, Id userId) {
Invoice__Share share = new Invoice__Share(
ParentId = invoiceId,
UserOrGroupId = userId,
AccessLevel = 'Read',
RowCause = Schema.Invoice__Share.RowCause.Manual
);
Database.SaveResult result = Database.insert(share, false);
if (!result.isSuccess()) {
System.debug(result.getErrors()[0].getMessage());
}
}Choosing a mechanism
Prefer the least complex option:
- Use teams for record-specific collaboration.
- Use sharing rules for stable owner- or criteria-based access.
- Use manual sharing for occasional individual grants.
- Use Apex sharing for repeatable, application-controlled decisions.
Manual shares can disappear when ownership changes. Avoid using Apex when a rule or team clearly expresses the requirement.
Exercise
A user has Read permission on Opportunity but cannot see a record. What should you check first?
Show answer
Check the org-wide default, record ownership, role hierarchy, teams, sharing rules, manual shares, and the user's group membership.