+ Start a Discussion
MC34MC34 

Needs help with trigger to update the counter field on Case Object.

Hi Awesome Developers, 

On case object I have created the number field Times_Reopened__c (default value is set as 0) 

in this I need to add counter of 1.2.3...so on depending number of times the new child record Clarification_Question__c is created for the case.

AND

Also, to check checkbox field on cases Clarification_Validation__c  = TRUE 

However, there are conditions:

The counter should only add when Clarification_Question__c reord is created of Type__c = 'Proof' (that is picklist field on Clarification_Question__c object) 

Busienss case: We have dedicated (Repeat Customer Proof Issues team Queue) that will take cases that are reopened for proof questons more than 2 times. Usually when cases are closed , they can get reopened when Clarification_Question__c records are created for them. This means if customer sends the questions after case is already closed. 

My objective: I would like to use Times_Reopened__c field value (Greater than 2) in the case assignment rules to route these cases to Repeat Customer Issues team.

As apex trigs are quicker than process builder or wfs this I think should be done by trigger. In the past process builder have been very slow and buggy so I am want to use trigger. 

Thanks in advance, 

MC34

Abdul KhatriAbdul Khatri
Hi MC34

Here is the trigger you requested. I hope this is what you are looking for.
 
trigger ClarificationQuestionTrigger on Clarification_Question__c (after insert) 
{
    List<Case> caseToUpdateList = new List<Case>();
    
    for(Clarification_Question__c cqRec : Trigger.new){
        
        if(cqRec.Type__c == 'Proof'){
            Case caseToUpdate = cqRec.Case__c;
            caseToUpdate.Times_Reopened__c = caseToUpdate.Times_Reopened__c + 1;
            
            caseToUpdateList.add(caseToUpdate);
        }
    }
    
    if(!caseToUpdateList.isEmpty())
        update caseToUpdateList;

}

I hope this help.