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 

convert apex trigger to class

I need to conver this triger to a class. get stuck on the after delete part.

trigger CCHIQPromotion on Quote_Promotion__c (after insert, after update, after 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,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') 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.CCH_Axcess_IQ_Promotion__c = true;
        }
        else
        {
       myParentProposal.CCH_Axcess_IQ_Promotion__c = false;
       }
    }
    update parentProposal.values();
    }
    
if(Trigger.IsInsert)
{
    for (Quote_Promotion__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.new){
         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.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
   } 
   if(Trigger.IsUpdate)
{
    for (Quote_Promotion__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.new){
         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.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
   } 
   }
Raj VakatiRaj Vakati
Try this code
 
trigger CCHIQPromotion on Quote_Promotion__c (after insert, after update, after delete) {

    If(trigger.Isdelete){
		CCHIQPromotion.afterDelete( Trigger.old) ; 
    }
    
if(Trigger.IsInsert)
{
	
	CCHIQPromotion.afterInsert( Trigger.new);
   
   } 
   if(Trigger.IsUpdate)
{
   	CCHIQPromotion.afterUpdate( Trigger.new);

   } 
   }
 
public class CCHIQPromotion{


public static Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
 public static   List<Id> listIds = new List<Id>();
 public static   List<Id> LineItems = new List<Id>();
    
 public static void afterDelete(List<Quote_Promotion__c> oldVal){
	  
	  
	  for (Quote_Promotion__c childObj :oldVal) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: oldVal){
         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.CCH_Axcess_IQ_Promotion__c = true;
        }
        else
        {
       myParentProposal.CCH_Axcess_IQ_Promotion__c = false;
       }
    }
    update parentProposal.values();
 }
 
 
 public static void afterInsert(List<Quote_Promotion__c> newValu){
	  for (Quote_Promotion__c childObj : newValu) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo:newValu){
         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.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
 }
   
   
   public static void afterUpdate(List<Quote_Promotion__c> newValu){
	  for (Quote_Promotion__c childObj : newValu) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: newValu){
         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.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
 }
   
}