Skip to main content
hema priya (.qr) 님이 #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개
  1. 2015년 3월 24일 오후 7: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