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
Jim MontgomeryJim Montgomery 

If trigger Isdelete code not working

Cannot find out why on a delete the checkbox is not being updated to false.

trigger HasSFTRPromotion on Quote_Promotion__c (after insert, after update, before delete) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    
    If(trigger.Isdelete){
for (Quote_Promotion__c childObj : Trigger.old) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,HasSFTRPromotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c IN('26645', '26646', '26647', '26648', '26649', '26650', '26651', '26652', '26653', '26654', '26655', '26656'
)) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.old){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.HasSFTRPromotion__c = true;
        }
        else
        {
       myParentProposal.HasSFTRPromotion__c = false;
       }
    }
    update parentProposal.values();
    }
MagulanDuraipandianMagulanDuraipandian
Hi,
Instead of updating the map, add the records to a list and update it.

--
Magulan Duraipandian
www.infallibletechie.com