• Muthu Samy
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Can somebody help me on setting a custom validation using trigger on case object ? 

Want to restrict users adding more than 500 children cases to parent case.
Hi, 

I'm creating visualforce page where I'll be displaying some information about case contact record. I'm adding this page to service console as a custom component. So, if I navigate between any tabs within console I get the information on visualforce page or component by selected case tab. Its working fine once I open the case tab from list view or navigate between tabs. When I refresh the page or during the initial loading, its not getting the active tab's Id so not showing any info. 

What console method I should use for it ? 
Hey guys,

I got requirement to have automation on case object. This particular requirement is just update all child cases status to same as parent case when it is updated.

I tried with process builder but it cannot handle if case has 500+ childs. So I'm trying with trigger.

trigger caseStatusSync on Case (before update) {

Set<Id> casesToProcess = new Set<Id>();

for(case c : Trigger.new){
    if( 
         (Trigger.newmap.get(c.id).status != Trigger.oldmap.get(c.id).status) 
       &&(
            trigger.newmap.get(c.id).status.containsIgnoreCase('Escalated')
         || trigger.newmap.get(c.id).status.containsIgnoreCase('Resolved')
         )
       )
    {
        casesToProcess.add(c.id);
    }
}

list<case> childcases = [select id,status,parentid from case where parentid in :casesToProcess ];
list<case> childCasesToUpdate = new list<case>();
    for(case cs:trigger.new){
    for(case c:childcases){
        c.status= trigger.newmap.get(cs.id).status;
        childCasesToUpdate.add(c);
    }
    }
    update childCasesToUpdate;
}

I think nested for loops are not recommended, so the problem here is, how to get rid of nested for loops ?  

Any other advice/change to the above code will be greatly helpful for me thanks.
Can somebody help me on setting a custom validation using trigger on case object ? 

Want to restrict users adding more than 500 children cases to parent case.
Hey guys,

I got requirement to have automation on case object. This particular requirement is just update all child cases status to same as parent case when it is updated.

I tried with process builder but it cannot handle if case has 500+ childs. So I'm trying with trigger.

trigger caseStatusSync on Case (before update) {

Set<Id> casesToProcess = new Set<Id>();

for(case c : Trigger.new){
    if( 
         (Trigger.newmap.get(c.id).status != Trigger.oldmap.get(c.id).status) 
       &&(
            trigger.newmap.get(c.id).status.containsIgnoreCase('Escalated')
         || trigger.newmap.get(c.id).status.containsIgnoreCase('Resolved')
         )
       )
    {
        casesToProcess.add(c.id);
    }
}

list<case> childcases = [select id,status,parentid from case where parentid in :casesToProcess ];
list<case> childCasesToUpdate = new list<case>();
    for(case cs:trigger.new){
    for(case c:childcases){
        c.status= trigger.newmap.get(cs.id).status;
        childCasesToUpdate.add(c);
    }
    }
    update childCasesToUpdate;
}

I think nested for loops are not recommended, so the problem here is, how to get rid of nested for loops ?  

Any other advice/change to the above code will be greatly helpful for me thanks.