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
Agnibha Chakrabarti 10Agnibha Chakrabarti 10 

validation rute on junction object

hi,
i have 3 objects, 
1.Batch
2.student
3.student batch junction

now,my requirement is- after a batch is completed(a checkbox is checked), no one candelete the record of Student related to that batch.
User-added imageI wrote a validation rule on Student batch junction-- (Batch__r.complted__c =true) && (  ISNULL(Student__r.Id ))
but it is not working
Satya Prakash ChoudharySatya Prakash Choudhary
If User has delete right of Student object, and delete button is their on UI then you can not stop just by using the validation rules.
You should try options like:

1. Write a trigger(before delete) event and then check the respected Studnet batch junction>>batch object status completed or not. Based on that use adderror function to stop users from deleting.

2. If just want to control from UI, can try to create anothe record type for student without any button. Update the record type of student record using apes on Batch object trigger when ever batch is getting completed.
Agnibha Chakrabarti 10Agnibha Chakrabarti 10
hi Satya,
following your option 1 i wrote a trigger
trigger error_delete on Student_Batch_Junction__c (before delete) {
 
 
    for(Student_Batch_Junction__c d:Trigger.old){
        
        if(d.Batch__r.complted__c==true){
         d.adderror('cant be deleted');
    }
    }
}

but it is not working!! can you help me with this?
​​​​​​​