Sunday, May 5, 2013

AccountShare Object


Recipe: Definition of AccountShare Object

Discussion:
At times, users may need to manage their record Sharing tables via the API.
For example, if an administrator wishes to remove all manually-assigned Territories from Accounts or Opportunities, it may be inconvenient to manage this change via the GUI.  Instead, the admin may prefer to delete these references in mass.  This would be done by accessing the Share tables through the API (for example, via the DataLoader).  The administrator would look for all records with a ROWCAUSE of TerritoryManual and delete these records.

Explanations of Fields of AccountShare object:
When accessing "Share" tables via the API, there are a number of columns that may not be immediately familiar.  Below are descriptions of each column and the possible values (the following refer to the AccountShare table, but the structure is very similar for other Share tables, such as OpportunityShare):

1. ID
This is the unique record ID for the AccountShare record.

2. ACCOUNTID
This column stores the IDs for the Account records being shared.  There may be multiple rows with the same AccountID value, as each Account record might be shared with more than one User or Group.

3. USERORGROUPID
This column stores the IDs for the User or Group to whom the Account record is shared.

4. ACCOUNTACCESSLEVEL
This column determines the access level granted for the Account record to the specified User or Group.
Values are:
A. All (Full access).
B. Edit (Read/Write).
C. Read (ReadOnly).

5. OPPORTUNITYACCESSLEVEL
This column determines the access level granted - for the Opportunities associated with this Account record - to the specified User or Group.
Values are:
A. Edit (Read/Write).
B. Read (ReadOnly).
C. None (No sharing granted).

6. CASEACCESSLEVEL
This column determines the access level granted - for the Cases associated with this Account record - to the specified User or Group.
Values are:
A. Edit (Read/Write).
B. Read (ReadOnly).
C. None (No sharing granted).

7. CONTACTACCESSLEVEL
This column determines the access level granted - for the Contacts associated with this Account record - to the specified User or Group.
Values are:
A. Edit (Read/Write)
B. Read (ReadOnly).
C. None (No sharing granted).

8. ROWCAUSE
This column explains *why* the Account record is shared to the specified User or Group.
Values are:
A. Owner (the specified User is the record owner).
B. ImplicitParent (a child record related to this Account is owned by the specified User).
C. Team (the specified User is an Account Team member).
D. Manual (sharing was manually granted to the specified User).
E. TerritoryManual (the Account record was manually assigned to a Territory).
F. Territory (a Territory assignment rule granted access for this Account record to the specified Group.  Note: records marked as Territory cannot be edited/deleted via DataLoader/API).

Reference Help Link for Account Share Object:
How do I interpret 'Share' tables?
http://help.salesforce.com/apex/HTViewSolution?id=000004856&language=en_US