Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void OnAfterObjectInsert(List<Object__c> insertRecords) {
- List<Object__Share> newShares = new List<Object__Share>();
- List<AccountShare> clientShares = [SELECT Id,AccountId,RowCause,UserOrGroupId FROM AccountShare WHERE AccountId = :insertRecords[0].Client__c];
- for (AccountShare cs : clientShares) {
- if(cs.UserOrGroupId != Userinfo.getUserId()) {
- Object__Share curShare = new Object__Share();
- curShare.ParentId = insertRecords[0].id;
- curShare.RowCause = 'Test__c'; //or Schema.Object__Share.RowCause.Test__c;
- curShare.UserOrGroupId = cs.UserOrGroupId;
- curShare.AccessLevel = 'Edit';
- newShares.add(curShare);
- }
- }
- insert newShares;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement