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

Trigger Help


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..

John PipkinJohn Pipkin
What's the relationship between object?

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){

	//query the record ids and assign to map
	Map<ID,ObjectA> objAMap = new Map<ID,ObjectA>();

		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){
	//delete the records
	    delete deleteRecords;

This won't be extremely helpful unless we know how all of the objects are related.
Thanks a lot John..

There is 'Lookup' relationship between 'Case'  and the associated records of 'A,B,C'..

Appreciate your help..

John PipkinJohn Pipkin
Cool. That framework should work then. You'll just need to add in the other objects in the same way. 

Happy coding!