Skip to main content
Hi all,

Here is my scenario. I need to give access to the users to children records B if they have access to the parent record A. A and B are in lookup relation. and the owner of A is not this user. Its an admin user. Does anyone have any code sample or starting point I can refer to(other than documentation)? I know it will be a trigger but the problem is the child record won't even exist when they have access to the parent record. The child records are created later,So  I can give access to child record on creation of child records but I am trying to figure out what happens when the user looses access to parent record, they shouldnt see child records either. 

Any help is highly appreciated.

Thank you
2 个回答
  1. 2019年9月9日 14:23
    Hello, 

    a solution it's to create a trigger after insert on the child and copy/past parents objet share to child objet share with a criteria : 

     list<ParentObjetShare> listParentShare = [select id, UserOrGroupId, ParentId

                                                       From ParentObjetShare where XXXXXX];

    list<ChildObjetShare> listChildShare = new ChildObjetShare();

    For (ParentObjetShare PS: listParentShare){

     

       If (YYYY == ZZZZ) {

          ChildShare CS;

         CS.ParentId = PS.ParentID;

          CS.UserOrGroupId = PS.UserOrGroupId;

           CS.RowCause = PS.RowCause;

           CS.AccessLevel = PS.AccessLevel ;

           listChildShare .add(CS);

       }

    }

    Insert listChildShare; 
0/9000