function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brandon Bridges 16Brandon Bridges 16 

Null pointer exception on Before Update? How is this possible?

*/trigger FirstContactResolution on Case(before insert,before update){/*
/*	*/for(case c:Trigger.New){//Trigger.New grabs updated information/* 
/*    	*/dateTime now=System.Now();//Assess current time to be used throughout this trigger/*
/*//Phone/Chat-First Contact Resolution Logic/*
* 		*/if(c!=null){
/*			*/if((c.Origin.contains('Phone')||c.Origin.contains('Chat'))&&(!c.Origin.contains('CP')))/*
 *			*/{/*
 *				*/if(c.Status=='Solved'){/*
 *	    			*/if(Trigger.isUpdate){/*
 *						*/c.ElapsedTime__c=/*
 * 	   					*/(Double.valueOf(now.getTime())-Double.valueOf(c.createddate.getTime()))/1000/60;/*
 * 	   					//Current datetime minus createdDate, convert to minute format from milliseconds
 * 	   					*/if(c.ElapsedTime__c<61){/*
 *      	    			*/c.First_Contact_Resolution__c=True;/*
 *          	    		*/c.First_Solve_DateTime__c=now;/*
 *          			*/}else{c.First_Contact_Resolution__c=False;}/*
 *					*/}/*                                                            
 *      			*/if(Trigger.isInsert){/*
 *						*/c.ElapsedTime__c=0;/*
 *						*/c.First_Contact_Resolution__c=True;/*
 *    					*/c.First_Solve_DateTime__c=now;/*
 *					*/}/*	  
 *				*/}else{c.First_Contact_Resolution__c=False;}/*
 *	 	 	*/}/*
 *		*/}/*
 *	*/}/*

 
Best Answer chosen by Brandon Bridges 16
Antonio Jesús Criado ManzanequeAntonio Jesús Criado Manzaneque
Probably you are referencing to the origin field and it is empty because you haven't insert the case yet and you don't have it initiated, so debug this field (system.debug(c.Origin)) and make sure that.

All Answers

Brandon Bridges 16Brandon Bridges 16

The error is thrown on line 6.

System.NullPointerException: Attempt to de-reference a null object: Trigger.FirstContactResolution: line 6, column 1

Antonio Jesús Criado ManzanequeAntonio Jesús Criado Manzaneque
Probably you are referencing to the origin field and it is empty because you haven't insert the case yet and you don't have it initiated, so debug this field (system.debug(c.Origin)) and make sure that.
This was selected as the best answer