You need to sign in to do that
Don't have an account?
kcharubin
System.NullPointerException: Attempt to de-reference a null object
Hello I am a beginner developer. I have implemented an apex trigger that counts all related Consumer Lead records.
I am getting this error when I try to create a new Lead Request record
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger rollupConsumerLeads caused an unexpected exception, contact your administrator: rollupConsumerLeads: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.rollupConsumerLeads: line 5, column 1
Review all error messages below to correct your data.
Apex trigger rollupConsumerLeads caused an unexpected exception, contact your administrator: rollupConsumerLeads: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.rollupConsumerLeads: line 5, column 1
trigger rollupConsumerLeads on Lead_Request__c (before insert, before update) { for(Lead_Request__c p:Trigger.new) p.Leads_Given_NEW__c = 0; for(Consumer_Leads__c c:[select id,Lead_Request_NEW__c from Consumer_Leads__c where Lead_Request_NEW__c in :Trigger.new]) Trigger.newMap.get(c.Lead_Request_NEW__c).Leads_Given_NEW__c++; }
Any help would be appricciated.
After some researching and trial and error I found a solution to my problem.
The querry was returning a null value for some reason causing a System.NullPointerException.
To fix the issue I surrounded that part of code withe a try catch statement.
Here is the working code.
When it finds a null value it ignores it
All Answers
After some researching and trial and error I found a solution to my problem.
The querry was returning a null value for some reason causing a System.NullPointerException.
To fix the issue I surrounded that part of code withe a try catch statement.
Here is the working code.
When it finds a null value it ignores it
http://technozchamps.blogspot.com/2015/02/caused-by-systemnullpointerexception.html