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
Steven Wellman 28Steven Wellman 28 

Trigger not updating field

I'm trying to mark a checkbox as false on the account when a child record is deleted but the field isn't updating. Here's my code:
trigger RatePlanDeletion on Zuora__SubscriptionRatePlan__c (after delete) {
	// Make a list of the deleted subscription rate plans
	List<Zuora__SubscriptionRatePlan__c> deletedRatePlan = [SELECT Id,
               Name,
               Zuora__Account__r.Local_Listings__c,
               Zuora__Account__r.Engage__c,
               Zuora__Account__r.SEO__c,
               Zuora__Account__r.Social_Ads__c,
               Zuora__Account__r.Social_Posting__c,
               Zuora__Account__r.Website_Product__c
               Zuora__SubscriptionRatePlan__c
               WHERE Id IN :Trigger.old];

	for (Zuora__SubscriptionRatePlan__c sub : deletedRatePlan) {

		// Get Trigger.new version of the rate plan
		Zuora__SubscriptionRatePlan__c subInTriggerNew = Trigger.newMap.get(sub.Id);		
		
		// Local Listings
		if ((sub.Name.contains('Marketing Essentials') || sub.Name.contains('Local Listings'))) {
			subInTriggerNew.Zuora__Account__r.Local_Listings__c = false;
		}

		// Engage 
		if (sub.Name.contains('Engage')) {
			subInTriggerNew.Zuora__Account__r.Engage__c = false;
		}

		// Reviews
		if (sub.Name.contains('Review')) {
			subInTriggerNew.Zuora__Account__r.Reviews__c = false;
		}

		// SEO
		if (sub.Name.contains('SEO')) {
			subInTriggerNew.Zuora__Account__r.SEO__c = false;
		}

		// Social Ads
		if (sub.Name.contains('Social Ads')) {
			subInTriggerNew.Zuora__Account__r.Social_Ads__c = false;
		}

		// Social Posting
		if (sub.Name.contains('Social Posting')) {
			subInTriggerNew.Zuora__Account__r.Social_Posting__c = false;
		}

		// Website
		if (sub.Name.contains('Website')) {
			subInTriggerNew.Zuora__Account__r.Website_Product__c = false;
		}
	}
}
Sorry, I'm new to working with deleted records and not sure what I'm missing. Thanks in advance for your help!
Alain CabonAlain Cabon
Hi,

It just lacks a new collection and an update.

Before the loop: List<Zuora__SubscriptionRatePlan__c> newRatePlan = new List<Zuora__SubscriptionRatePlan__c>();
End of the loop (inside): newRatePlan.add(subInTriggerNew);
After the loop: update newRatePlan;
Steven Wellman 28Steven Wellman 28
I tried that and it still isn't working. Here's the code:
trigger RatePlanDeletion on Zuora__SubscriptionRatePlan__c (after delete) {

	// Make a list of the deleted subscription rate plans
	List<Zuora__SubscriptionRatePlan__c> deletedRatePlan = [SELECT Id,
Name,
Zuora__Account__r.Local_Listings__c,
Zuora__Account__r.Engage__c,
Zuora__Account__r.SEO__c,
Zuora__Account__r.Social_Ads__c,
Zuora__Account__r.Social_Posting__c,
Zuora__Account__r.Website_Product__c
Zuora__SubscriptionRatePlan__c
IN :Trigger.old];

	List<Zuora__SubscriptionRatePlan__c> newRatePlan = new List<Zuora__SubscriptionRatePlan__c>();

	for (Zuora__SubscriptionRatePlan__c sub : deletedRatePlan) {

		// Get Trigger.new version of the rate plan
		Zuora__SubscriptionRatePlan__c subInTriggerNew = Trigger.newMap.get(sub.Id);		
		
		// Local Listings
		if ((sub.Name.contains('Marketing Essentials') || sub.Name.contains('Local Listings'))) {
			subInTriggerNew.Zuora__Account__r.Local_Listings__c = false;
		}

		// Engage 
		if (sub.Name.contains('Engage')) {
			subInTriggerNew.Zuora__Account__r.Engage__c = false;
		}

		// Reviews
		if (sub.Name.contains('Review')) {
			subInTriggerNew.Zuora__Account__r.Reviews__c = false;
		}

		// SEO
		if (sub.Name.contains('SEO')) {
			subInTriggerNew.Zuora__Account__r.SEO__c = false;
		}

		// Social Ads
		if (sub.Name.contains('Social Ads')) {
			subInTriggerNew.Zuora__Account__r.Social_Ads__c = false;
		}

		// Social Posting
		if (sub.Name.contains('Social Posting')) {
			subInTriggerNew.Zuora__Account__r.Social_Posting__c = false;
		}

		// Website
		if (sub.Name.contains('Website')) {
			subInTriggerNew.Zuora__Account__r.Website_Product__c = false;
		}
		
		newRatePlan.add(subInTriggerNew);
	}
	update newRatePlan;
}

 
Raj VakatiRaj Vakati
Try like below .. Change it in all the conditions 
 
// Local Listings
		if ((sub.Name.contains('Marketing Essentials') || sub.Name.contains('Local Listings'))) {
			Zuora__SubscriptionRatePlan__c prs =subInTriggerNew.Zuora__Account__r;
			prs.Local_Listings__c = false;
		}