I need help with writing a trigger for deleting the associated records for example A,B,C records when a 'Case' record is deleted. Appreciate any code help..
Assuming it is lookups, the framework could look like this:
trigger deleteStuff on Case (before delete){
//get all record IDS you want to delete and store in set
Set<ID> ObjectAIds = new Set<ID>();
for(Case c :Trigger.Old){
ObjectAIds.add(c.ObjectALookup);
}
//query the record ids and assign to map
Map<ID,ObjectA> objAMap = new Map<ID,ObjectA>();
if(!ObjectAIds.isEmpty()){
objAMap = new Map<ID,ObjectA>([Select Id from ObjectA where Id in :ObjectAIds]);
}
//use the map get method to add the records into a list
List<ObjectA> deleteRecords = new List<ObjectA>();
for(Case c :Trigger.old){
deleteRecords.add(objAMap.get(c.ObjectALookup));
}
//delete the records
if(!deleteRecords.isEmpty())
delete deleteRecords;
}
This won't be extremely helpful unless we know how all of the objects are related.
Assuming it is lookups, the framework could look like this:
This won't be extremely helpful unless we know how all of the objects are related.
There is 'Lookup' relationship between 'Case' and the associated records of 'A,B,C'..
Appreciate your help..
Thanks
Happy coding!