Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public void OnAfterObjectInsert(List<Object__c> insertRecords) {
  2. List<Object__Share> newShares = new List<Object__Share>();
  3. List<AccountShare> clientShares = [SELECT Id,AccountId,RowCause,UserOrGroupId FROM AccountShare WHERE AccountId = :insertRecords[0].Client__c];
  4. for (AccountShare cs : clientShares) {
  5. if(cs.UserOrGroupId != Userinfo.getUserId()) {
  6. Object__Share curShare = new Object__Share();
  7. curShare.ParentId = insertRecords[0].id;
  8. curShare.RowCause = 'Test__c'; //or Schema.Object__Share.RowCause.Test__c;
  9. curShare.UserOrGroupId = cs.UserOrGroupId;
  10. curShare.AccessLevel = 'Edit';
  11. newShares.add(curShare);
  12. }
  13. }
  14. insert newShares;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement