describeSObjects(), create(), delete(), query(), retrieve(), update(), upsert()
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 |
|
AccountId |
|
CaseAccessLevel |
|
ContactAccessLevel |
|
IsDeleted |
|
OpportunityAccessLevel |
|
RowCause |
|
UserOrGroupId |
|
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.