Skip to main content
hema priya (.qr) preguntó en #Apex
It should not allowing me to close if the parent case records  if the child case status ids open...I am new to salesforce.please help me
1 respuesta
  1. 24 mar 2015, 19:11
    Your trigger will simply query all cases whose parent id is in the new one and check their status

     

    trigger parentCheck on Case (before update) {

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

    for (Case c : Trigger.new) {

    if (c.Status == 'Closed') {

    caseIds.add(c.Id);

    }

    }

    if (!caseIds.isEmpty()) {

    Map<Id, List<Case>> caseToParentMap = new Map<Id, List<Case>>();

    for (Id id : caseIds) {

    caseToParentMap.put(id, new List<Case>());

    }

    for (Case c : [

    select ParentId

    from Case

    where ParentId in :caseIds and

    Status != 'Closed'

    ]) {

    caseToParentMap.get(c.ParentId).add(c);

    }

    for (Id id : caseIds) {

    if (!caseToParentMap.get(id).isEmpty()) {

    Trigger.newMap.get(id).addError('Case has unclosed children');

    }

    }

    }

    }

    NOTE: This code has not been tested and may contain typographical or logical errors
0/9000