function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shruti NigamShruti Nigam 

How to unlock child record for certain profile?

Hi all i used lookup relationship and i am locking child record using this trigger.
The following trigger prevents any changes to the children while this Locked__c box is checked:
trigger DetailLockCheck on Detail__c (before delete, before insert, before update) {

     Set<Id> masterIdSet = new Set<Id>();

     for (Detail__c each : trigger.new)
          masterIdSet.add(each.Master__c);

 

     Map<String, Boolean> masterMap = new Map<String, Boolean>();

 

     for (Master__c each : [select Id, Locked__c from Master__c where Id in :masterIdSet])
          masterMap.put(each.Id, each.Locked__c);

     for (Detail__c each : trigger.new) {
          if (masterMap.get(each.Master__c))
               each.addError('Master Record is Locked. Details cannot be created, edited, or deleted.');
     }
}

What i want to do is that i need to able to edit record for some profile.


Thank you.
Anant KamatAnant Kamat
From the trigger I understand that you are using the Locked__c field to prevent the field from getting edited. Instead you can use a simple validation rule to prevent the record from being edited using the same Locked__c field value instead of a trigger. In the validation all you need to do is put Profile check so that validation rule does not fire when user with those profiles try to modify the record.