AccountShare

Represents a sharing entry on an Account.

Supported Calls

describeSObjects(), create(), delete(), query(), retrieve(), update(), upsert()

Special Access Rules

Customer Portal users can't access this object.

Fields

The properties available for some fields depend on the default organization-wide sharing settings. The properties listed are true for the default settings of such fields.

Field Details
AccountAccessLevel
Type
picklist
Properties
Filter, Group, Restricted picklist, Sort
Description
Level of access that the User or Group has to the Account. The possible values are:
  • Read
  • Edit
  • All (This value isn't valid for create or update calls.)
This field must be set to an access level that is at least equal to the organization’s default Account access level. In addition, either this field, the OpportunityAccessLevel field, or the CaseAccessLevel field must be set higher than the organization’s default access level.
AccountId
Type
reference
Properties
Filter, Group, Sort
Description
ID of the Account associated with this sharing entry. This field can't be updated.
CaseAccessLevel
Type
picklist
Properties
Filter, Group, Restricted picklist, Sort
Description
Level of access that the User or Group has to cases associated with the account. The possible values are:
  • None
  • Read
  • Edit
This field must be set to an access level that is at least equal to the organization’s default CaseAccessLevel. This field can't be updated via the API if the AccountAccessLevel field is set to All. You can't update this field for the associated account owner via the API. You must update the account owner’s CaseAccessLevel via the Salesforce user interface.
ContactAccessLevel
Type
picklist
Properties
Filter, Group, Nillable, Restricted picklist, Sort
Description
Level of access that the User or Group has to contacts associated with the account. The possible values are:
  • None
  • Read
  • Edit
This field must be set to an access level that is at least equal to the organization’s default ContactAccessLevel. This field can't be updated via the API if the ContactAccessLevel field is set to “Controlled by Parent.” You can't update this field for the associated account owner using the API. You must update the account owner’s ContactAccessLevel via the Salesforce user interface.
IsDeleted
Type
boolean
Properties
Defaulted on create, Filter
Description
Indicates whether the object has been moved to the Recycle Bin (true) or not (false). Label is Deleted.
OpportunityAccessLevel
Type
picklist
Properties
Filter, Group, Restricted picklist, Sort
Description
Level of access that the User or Group has to opportunities associated with the Account. The possible values are:
  • None
  • Read
  • Edit

This field must be set to an access level that is at least equal to the organization’s default opportunity access level. This field can’t be updated via the API if the AccountAccessLevel field is set to All. You can't use the API to update this field for the associated Account owner. You must update the Account owner’s opportunityAccessLevel via the Salesforce user interface.

RowCause
Type
picklist
Properties
Filter, Group, Restricted picklist, Sort
Description
Reason that this sharing entry exists. You can only write to this field when its value is either omitted or set to Manual (default). You can create a value for this field in API versions 32.0 and later with the correct organization-wide sharing settings.
Valid values include:
  • Manual—The User or Group has access because a User with “All” access manually shared the Account with the user or group.
  • ImplicitParent—The User or Group has access because they’re the owner of or have sharing access to records related to the account, such as opportunities, cases, contacts, contracts, or orders.
  • Owner—The User is the owner of the Account
  • Team—The User or Group has team access (is an AccountTeamMember).
  • Rule—The User or Group has access via an Account sharing rule.
UserOrGroupId
Type
reference
Properties
Filter, Group, Sort
Description
ID of the User or Group that has been given access to the Account. This field can't be updated.

Usage

This object allows you to determine which users and groups can view or edit Account records owned by other users.

If you attempt to create an AccountShare record that matches an existing record, the request updates any modified fields and returns the existing record.

For example, the following code finds all accounts owned by a user and manually shares them to a portal user.

QueryResult result = conn.query("SELECT Id FROM Account WHERE OwnerId = '005D0000001LPFB'");
// Create a new AccountShare object
List<AccountShare> shares = new ArrayList<AccountShare>();
for (SObject rec : result.getRecords()) {  
     AccountShare share = new AccountShare();
    share.setAccountId(rec.getId());
    //Set the portal user Id to share the accounts with
    share.setUserOrGroupId("003D000000QA8Tl");
    share.setAccountAccessLevel("Edit");
    share.setOpportunityAccessLevel("Read");
    share.setCaseAccessLevel("Edit");
    shares.add(share);
}
conn.create(shares.toArray(new AccountShare[shares.size()]));

This code shares the accounts that the user owns at the time, but not those accounts that are owned later. For these types of shares, use an owner-based sharing rule, such as AccountOwnerSharingRule.

If an account is shared in multiple ways with a user, you don’t always see multiple sharing records. If a user has access to an account for one or more of the following RowCause values, the records in the AccountShare object are compressed into one record with the highest level of access.
  • ImplicitParent
  • Manual
  • Owner

See Also