You need to sign in to do that
Don't have an account?
Ryan Greene
Error on Deployment CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
I tried deploying this Trigger to my production this morning. It is a simple trigger to convert any names to Propper case, first and last. It seems like another APEX Class is interfeering with the deployment. The error points to a managed package I am not able to edit. Any ideas on how to get around this error?
Full Error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Proper: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Proper: line 5, column 1: []
Stack Trace: Class.dlrs.RollupService.testHandler: line 277, column 1 Class.dlrs_LeadTest.testTrigger: line 11, column 1
APEX Trigger:
Full Error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Proper: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Proper: line 5, column 1: []
Stack Trace: Class.dlrs.RollupService.testHandler: line 277, column 1 Class.dlrs_LeadTest.testTrigger: line 11, column 1
APEX Trigger:
trigger Proper on Lead (before insert) { for(Lead l : Trigger.new){ if(l.FirstName != null) l.FirstName = l.FirstName.subString(0 ,1).ToUpperCase() + l.FirstName.subString(1); l.LastName = l.LastName.subString(0 ,1).ToUpperCase() + l.LastName.subString(1); } }
Hi Ryan,
If you look closely at the exception you posted, there is a null pointer exception thrown at line 5 in your trigger.
It looks like LastName is null in some cases. You're checking for FirstName being null, which is great. However, you forgot about LastName.
I also prefer to use String.isEmpty instead of != null in cases like this, as isEmpty checks for nulls AND empty strings.
Try the following trigger instead:
All Answers
Hi Ryan,
If you look closely at the exception you posted, there is a null pointer exception thrown at line 5 in your trigger.
It looks like LastName is null in some cases. You're checking for FirstName being null, which is great. However, you forgot about LastName.
I also prefer to use String.isEmpty instead of != null in cases like this, as isEmpty checks for nulls AND empty strings.
Try the following trigger instead:
Seems like the LastName is not set. Add a not null check on LastName too to fix the issue.
Run this code to see the error:
No Error when LastName is set:
Good tip on the isEmpty too. Deployed new code without errors