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
XIOXIO 

Issue with Rollup Apex Trigger

I need the trigger below to activate only if the opportunity is RecordType "Conference". Any assistance is greatly apprecitated!

 
trigger RollUpOpportunity on Opportunity (after insert,after update, after delete,after undelete) {
    
    List<id> ParentIds = new List<id>();
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){
        For(Opportunity Opp : Trigger.new){
            ParentIds.add(Opp.Discount_code_LU__c);
        }
    }
    if(Trigger.isDelete){
        For(Opportunity Opp : Trigger.old){
            ParentIds.add(Opp.Discount_code_LU__c);
        }
    }
    List<Product2> ProductsToUpdate = new List<Product2>();
    decimal sum = 0;
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate|| trigger.isdelete){
        For(Product2 q : [SELECT Related_Conference_Opportunities__c ,(SELECT id FROM Opportunities__r WHERE Voucher_Canceled__c = False)
         FROM Product2 WHERE id =: ParentIds]){
            sum = 0;
            for(Opportunity p : q.Opportunities__r){
                
                   sum = sum + 1;
            }
            q.Related_Conference_Opportunities__c = sum;
            ProductsToUpdate.add(q);
        }
        try{
            update ProductsToUpdate;
        }Catch(Exception e){
            System.debug('Exception :'+e.getMessage());
        }
    }
}


 
Best Answer chosen by XIO
XIOXIO
Figured it out: WHERE Voucher_Canceled__c = False AND RecordTypeId =