• Calvin Moodley 11
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
Hi All,
I have created a trigger that when an order is in the Status[Order Submitted] and the create case field is true i want a case to be created.
However there are multiple cases being created against the record 
Please see below triger and classes. :
My Trigger
triggerHandler 
triggerFunction

trigger caseOrder on ccrz__E_Order__c (after insert, after update) {
     if(trigger.isInsert){
        caseOrderTriggerHandler.isAfterInsert(Trigger.new);
    }
        if(trigger.isUpdate){
            caseOrderTriggerHandler.isAfterInsert(Trigger.new);
        }

}

public class caseOrderTriggerHandler {
    public static void isAfterInsert (List<ccrz__E_Order__c>ords) {
        caseOrderTriggerFunction.createCase(ords);
    }

}

public class caseOrderTriggerFunction {
    
 
    public static void createCase(List<ccrz__E_Order__c>ords){
        Date ordCreatedDate = date.today();
        List<ccrz__E_Order__c> todaysOrds = [SELECT id, ccrz__OrderStatus__c, Create_Case__c,ccrz__OrderDate__c,ccrz__Contact__c,ccrz__Account__c
                                             FROM ccrz__E_Order__c
                                             WHERE id IN :ords
                                             AND ccrz__OrderDate__c = :ordCreatedDate];
        
        List<Case> myCase = new List <Case>();
        
        for(ccrz__E_Order__c myOrds : todaysOrds) {
            
            if(myOrds.ccrz__OrderStatus__c == 'Order Submitted' && myOrds.Create_Case__c == true ) {
                
                case c = new case();
                c.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('General Enquiry').getRecordTypeId();
                c.Reason = 'General Enquiry';
                c.Case_Reason__c ='orders';
                c.Status = 'New';
                c.Subject = 'order Submitted status';
                c.Case_Sub_Reason__c ='Incomplete Order Creation';
                c.Description ='Order Id: '+myOrds.Id+'related to account Id: '+myOrds.ccrz__Account__c+' has failed in SAP';
                c.ContactId = myOrds.ccrz__Contact__c;
                c.AccountId = myOrds.ccrz__Account__c;
                myCase.add(c);
                
                
            } 
        }
        if(mycase.size() == 1 ) {
            insert myCase;
        }
        
        
    }
    
        
}




 
Hi All,
I have created a trigger that when an order is in the Status[Order Submitted] and the create case field is true i want a case to be created.
However there are multiple cases being created against the record 
Please see below triger and classes. :
My Trigger
triggerHandler 
triggerFunction

trigger caseOrder on ccrz__E_Order__c (after insert, after update) {
     if(trigger.isInsert){
        caseOrderTriggerHandler.isAfterInsert(Trigger.new);
    }
        if(trigger.isUpdate){
            caseOrderTriggerHandler.isAfterInsert(Trigger.new);
        }

}

public class caseOrderTriggerHandler {
    public static void isAfterInsert (List<ccrz__E_Order__c>ords) {
        caseOrderTriggerFunction.createCase(ords);
    }

}

public class caseOrderTriggerFunction {
    
 
    public static void createCase(List<ccrz__E_Order__c>ords){
        Date ordCreatedDate = date.today();
        List<ccrz__E_Order__c> todaysOrds = [SELECT id, ccrz__OrderStatus__c, Create_Case__c,ccrz__OrderDate__c,ccrz__Contact__c,ccrz__Account__c
                                             FROM ccrz__E_Order__c
                                             WHERE id IN :ords
                                             AND ccrz__OrderDate__c = :ordCreatedDate];
        
        List<Case> myCase = new List <Case>();
        
        for(ccrz__E_Order__c myOrds : todaysOrds) {
            
            if(myOrds.ccrz__OrderStatus__c == 'Order Submitted' && myOrds.Create_Case__c == true ) {
                
                case c = new case();
                c.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('General Enquiry').getRecordTypeId();
                c.Reason = 'General Enquiry';
                c.Case_Reason__c ='orders';
                c.Status = 'New';
                c.Subject = 'order Submitted status';
                c.Case_Sub_Reason__c ='Incomplete Order Creation';
                c.Description ='Order Id: '+myOrds.Id+'related to account Id: '+myOrds.ccrz__Account__c+' has failed in SAP';
                c.ContactId = myOrds.ccrz__Contact__c;
                c.AccountId = myOrds.ccrz__Account__c;
                myCase.add(c);
                
                
            } 
        }
        if(mycase.size() == 1 ) {
            insert myCase;
        }
        
        
    }
    
        
}