+ Start a Discussion
Christopher PettittChristopher Pettitt 

Validation Rule to verify at least one Case Team Member

Trying to create a validation rule on the Case object that checks to see if there is at least one Case Team member before allowing the user to change the Status field to a specific value. Anyone have any ideas? Any help would be amazing! 
Best Answer chosen by Christopher Pettitt
Maharajan CMaharajan C
Hi Christopher,

We have to use the Trigger for you scenario:

trigger caseMemberValidation on Case (before update) {  
    set<Id> caseIds = new set<Id>();
    set<Id> casectmIds = new set<Id>();
    for(case cs : Trigger.New)
    {
        if(cs.Status != Trigger.OldMap.get(cs.Id).status)
        {
            caseIds.add(cs.Id);
        }
    }
    
    if(!caseIds.isEmpty())
    {    
        for(CaseTeamMember ctm : [Select Id,ParentId from CaseTeamMember where ParentId IN: caseIds])
        {
            casectmIds.add(ctm.ParentId);
        }
    
        for(case cs : Trigger.New)
        {
            if(!casectmIds.contains(cs.Id))
            {
                cs.addError( ' Case must have atleast one Team Member to change the Status ' );
            }
        }  
    }
}

Thanks,
Maharajan.C