You need to sign in to do that
Don't have an account?
Skeeter
trigger to prevent deleting child records
I'm trying to create a trigger to prevent deletion of a child record if the parent record has a status of approved. I'm not sure what I'm missing. on the testentry.add line it is saying invalid field test__c for SObject sheet__c
trigger PreventEntryDeletion on Test__c (before delete) { Set<ID> testentry = New Set<ID>(); List<sheet__c> l = [Select Id From sheet__c Where status = 'Approved' and Id IN :trigger.oldMap.KeySet()]; for(sheet__c objp : l) { testentry.add(objp.test__c); } For(test__c obja : trigger.old){ If(testentry.contains(obja.ID)) obja.addError('You cannot delete a test entry on an approved sheet.'); } }
Below is the sample code as per my understanding and hopefully it should work. I am assuming that Sheet__c is a parent object, Test__c is a child object and sheetid__c is a lookup field on Test__c which is related to Sheet__c parent object.