0

I am trying to create a trigger to update the parent casestatus when a child case is created. I have the below trigger on after insert like below

trigger setTISStatusFromTGS on Case (after insert) {
           
            ID recordTypeTGS                = Schema.SObjectType.Case.getRecordTypeInfosByName().get('TGS').getRecordTypeId();
            ID recordTypeTIS                = Schema.SObjectType.Case.getRecordTypeInfosByName().get('TIS').getRecordTypeId();
           
            Set<Id> parentIds = new Set<Id>(); 
            List<Case> csParentList = new List<Case>();
           
    for(Case newCase : trigger.new){
                if(newCase.RecordTypeId == recordTypeTGS && newCase.ParentId != '')
                {
                    parentIds.add(newCase.ParentId);
                }
           }           
            if(!parentIds.isEmpty())
            {
                csParentList = [Select Id, Status From Case Where Id In :parentIds and RecordTypeId =: recordTypeTIS ];
            }
           
           List<Case> csUpdateList = new List<Case>();
           for (Case cs : csParentList)
           {
               if(cs.Status != 'Closed' && cs.Status != 'Closed as Duplicate' )
               {
                   cs.Status = 'Pending-Internal';
                   csUpdateList.add(cs);
               }
           }
           
        if(csUpdateList.size()>0) {
                update csUpdateList;
            }
}

But when I tried to create the child record I get the error like below Review the errors on this page. setTISStatusFromTGS: execution of AfterInsert caused by: System.StringException: Invalid id: ()

Can anyone please suggest what I am missing here.

1
1

Recreated this in a developer org

enter image description here

Trigger.setTISStatusFromTGS: line 10, column 1 21:09:08.0 (14427671)|FATAL_ERROR|System.StringException: Invalid id:

Issue is coming at this line

if(newCase.RecordTypeId == recordTypeTGS && newCase.ParentId != '')

Changing newCase.ParentId != '' to newCase.ParentId!=null has fixed the issue

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