1

I have a Child and parent case. I have the following fields:

  • Reopen Flag (Checkbox field)
  • Case Reopened By (Drop down field)
    • The vales in Reopened By fields are Customer and Internal
  • Total Reopen Count
  • Customer Reopen Count
  • Internal Reopen Count

Details by Steps:

  1. Select Reopen Flag in Child Case
  2. Select Case Reopened By (Value: Customer) in Child Case
  3. Customer Reopen Count Field gets incremented by 1. in Child Case
  4. Total Reopen Count gets Incremented by 1. in Child Case
  5. Parent Case also gets updated.

Repeat the steps but it does not gets updated in Parent Case.

Change the Value in Case Reopened By - "Internal" in child Case then the values will get updated in Parent Case.

How to update Parent Case from child case every time Total Reopen Count and Customer Reopen Count/Internal Reopen Count gets updated.

trigger Update_Parent_Case on Case (after update) {

    map<string,case> case_map = new map<String,Case>();

    for(case cs : trigger.new){

        if(trigger.oldMap.get(cs.id).Total_Reopen_Count__c != cs.Total_Reopen_Count__c){            
            case_map.put(string.valueof(cs.ParentId),cs);
        }
    }


    list<case> to_update = new List<case>();
    if(case_map.size() > 0){
        for(case cc : [Select id,Case_Re_opened_By__c,Re_open_Flag__c, Customer_Re_open_Count__c,Internal_Re_open_Count__c from case where id in: case_map.keySet()]){
            case c = case_map.get(cc.id);
              cc.Case_Re_opened_By__c = c.Case_Re_opened_By__c;
             cc.Re_open_Flag__c = true;
            cc.Total_Reopen_Count__c = c.Total_Reopen_Count__c;
            cc.Customer_Re_open_Count__c = c.Customer_Re_open_Count__c;
               cc.Internal_Re_open_Count__c = Internal_Re_open_Count__c;     
         to_update.add(cc);
        }
        update to_update;
        case_map.clear();
    }

}
  • 3
    If you've solved your own problem, It's generally considered good form for you to post an answer to your question to go over what was wrong and how you fixed it. That way, if someone else has a similar issue, they can look at an answer for guidance. – Derek F Sep 19 '16 at 13:46
  • Also, +1 from me for including relevant details and your current code. – Derek F Sep 19 '16 at 13:48
  • Please see the changes i made in code which worked well for me... – srinivas ramachandrappa Sep 20 '16 at 7:10
  • That's great, but again, it would be more helpful to others if you posted it as an answer. – Derek F Sep 20 '16 at 11:54
0

Please Try out the below code

trigger Update_Parent_Case on Case (after update) {

    map<string,case> case_map = new map<String,Case>();

    for(case cs : trigger.new){

        if(trigger.oldMap.get(cs.id).Total_Reopen_Count__c != cs.Total_Reopen_Count__c){            
            case_map.put(string.valueof(cs.ParentId),cs);
        }
    }


    list<case> to_update = new List<case>();
    if(case_map.size() > 0){
        for(case cc : [Select id,Case_Re_opened_By__c,Re_open_Flag__c, Customer_Re_open_Count__c,Internal_Re_open_Count__c from case where id in: case_map.keySet()]){
            case c = case_map.get(cc.id);
            cc.Case_Re_opened_By__c = c.Case_Re_opened_By__c;
            cc.Re_open_Flag__c = true;
            cc.Total_Reopen_Count__c = c.Total_Reopen_Count__c;
            cc.Customer_Re_open_Count__c = c.Customer_Re_open_Count__c;
            cc.Internal_Re_open_Count__c = Internal_Re_open_Count__c;     
            to_update.add(cc);
        }
        update to_update;
        case_map.clear();
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.