You need to sign in to do that
Don't have an account?

Null pointer exception error in trigger on Case object
I have written below trigger to update case status when case is assigned from Queue to a user, but it is giving a null pointer exception @line 10.
The requirement is to update case status when case is assigned from a queue to a user.
The requirement is to update case status when case is assigned from a queue to a user.
trigger updateCase on Case (before update) { List<Case> newCaseList = new List<Case>() ; System.debug('@@newCase' + newCaseList); for(Case c : Trigger.new) { System.debug('@@@' + c); //just add few more null checks- If(c.status!=null && c.OwnerID.getsobjecttype()!=null) { if(c.OwnerID.getsobjecttype() == User.sobjecttype && c.Status == 'New') { if(Trigger.oldMap.get(c.Id).Owner.getsobjecttype() != User.sobjecttype) { c.Status = 'Working'; newCaseList.add(c); } System.debug('@@' + newCaseList); } } } if(newCaseList.size() > 0) { insert newCaseList; } }
Try with below code it will work as your event is before update no need to do DML on this .
For some concepts you can check below link it will help !!
Let me know if it helps!!
Thanks
Manoj
All Answers
Try with below code it will work as your event is before update no need to do DML on this .
For some concepts you can check below link it will help !!
Let me know if it helps!!
Thanks
Manoj
if(Trigger.oldMap.get(c.Id).OwnerId.getsobjecttype() != User.sobjecttype)
Thanks much for the help