I had master detailed relationship with the Case and Payment1,2 etc object. Now this relationship is changed to lookup. Now OWD for Case, Payment1,2 is Private. Now User is not able to access the old cases, basically unable to see any records of Payment1,2 at all.

Now I need to identify all child object records of that Case and need to make them a owner like as Case.

Could you please confirm what do I need to do ?

  • Make Child Object as Owner like Case?
  • Do I need to create Child Share Object ?

Here is the code

Set<Id> caseOwnerUpdatesSet = new Set<Id>();
caseOwnerUpdatesSet.add('KKK'); // Here will provide the list of Ids

Map<Id, Case> newCasesMap = new Map<Id,Case>([SELECT Id, OwnerId FROM Case WHERE Id IN ('KKK')]);

Map<Id, List<Payment1__c>> paymentsiInfoMap = new Map<Id, List<Payment1__c>>();

List<Payment1__c> payment1InfoToUpdateOwnerLst = new List<Payment1__c>();

for(Payment1__c si : [SELECT Id, OwnerId, Case__c 
                                     FROM Payment1__c 
                                     WHERE Case__c IN :caseOwnerUpdatesSet]){

    paymentsiInfoMap.put(si.Case__c, new List<Payment1__c>{si});


for(Case objCase : newCasesMap.values()){
    // check Owner to be updated present
    if(caseOwnerUpdatesSet.contains(objCase.Id) && paymentsiInfoMap.containsKey(objCase.Id)){
        for(Payment1__c si : paymentsiInfoMap.get(objCase.Id)){
            si.OwnerId = objCase.OwnerId;

    update payment1InfoToUpdateOwnerLst;

Map<Id, List<Payment_2__c>> si2InfoMap = new Map<Id, List<Payment_2__c>>();
List<Payment_2__c> payment2InfoToUpdateOwnerLst = new List<Payment_2__c>();

// Get all Service Info records for which owner has to be changed
for(Payment_2__c si2 : [SELECT Id, OwnerId, Case__c 
                                        FROM Payment_2__c
                                        WHERE Case__c IN :caseOwnerUpdatesSet]){
    si2InfoMap.put(si2.Case__c, new List<Payment_2__c>{si2});

for(Case objCase : newCasesMap.values()){
    // check Owner to be updated present
    if(caseOwnerUpdatesSet.contains(objCase.Id) && si2InfoMap.containsKey(objCase.Id)){
        for(Payment_2__c si2 : si2InfoMap.get(objCase.Id)){
            si2.OwnerId = objCase.OwnerId;

    update payment2InfoToUpdateOwnerLst;

Yes you need to:

  • propagate any owner change from Case to the child objects using e.g. a trigger
  • add sharing rules for the child objects

If the child objects make no sense without the Case object, you should also create your own "cascading delete" i.e. when the Case is deleted also delete the child objects.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.