You need to sign in to do that
Don't have an account?
Alekhya Mathukumilli 7
Attempt to de-reference a null object in Prod
my code works fine in UAT but when deployed in Production is throwing an error
Attempt to de-reference a null object
it works fine with other two objects i have in the code only with one object. I tried checking everything I could that is linked up with this.
All I am stuck is why is it working in UAT and not in Prod.
This is where I am getting an error in Prod
if(!comlist.isEmpty()){
for(Comliance_Checklist__c cl:comlist ){
cidset.add(cl.Id);
if(cl.Category__c=='Outside/ Waste Area'){
violationwrapper wr = new violationwrapper();
//wr.violationid = cl.Id;
wr.category = cl.Category__c;
wr.violationid = cl.ViolationId__c;
wr.violation = violationMap.get(cl.ViolationId__c).Violation__c;
wr.guidance = violationMap.get(cl.ViolationId__c).Guidance_to_Avoid_Violation__c ;
wr.penalty = violationMap.get(cl.ViolationId__c).Penalty__c;
wr.notes = cl.Notes__c;
wr.topic = cl.Topic_Discussed__c;
dsnyList.add(wr);
AllList.add(wr);
}
it says al line line 70 and line 70 is my "}"
Please help me with this.
Attempt to de-reference a null object
it works fine with other two objects i have in the code only with one object. I tried checking everything I could that is linked up with this.
All I am stuck is why is it working in UAT and not in Prod.
This is where I am getting an error in Prod
if(!comlist.isEmpty()){
for(Comliance_Checklist__c cl:comlist ){
cidset.add(cl.Id);
if(cl.Category__c=='Outside/ Waste Area'){
violationwrapper wr = new violationwrapper();
//wr.violationid = cl.Id;
wr.category = cl.Category__c;
wr.violationid = cl.ViolationId__c;
wr.violation = violationMap.get(cl.ViolationId__c).Violation__c;
wr.guidance = violationMap.get(cl.ViolationId__c).Guidance_to_Avoid_Violation__c ;
wr.penalty = violationMap.get(cl.ViolationId__c).Penalty__c;
wr.notes = cl.Notes__c;
wr.topic = cl.Topic_Discussed__c;
dsnyList.add(wr);
AllList.add(wr);
}
it says al line line 70 and line 70 is my "}"
Please help me with this.
You wrote these lines
wr.violation = violationMap.get(cl.ViolationId__c).Violation__c;
wr.guidance = violationMap.get(cl.ViolationId__c).Guidance_to_Avoid_Violation__c ;
wr.penalty = violationMap.get(cl.ViolationId__c).Penalty__c;
But you are not checking for key in the map.So it would be better if you add IF condition before getting values from the map.
Thanks.
Please let me know if it helps.
All Answers
So I see a couple possibilities, but it would be helpful if you post all the code to get more context.
From what I can tell, there's two spots that can cause a null dereferencing error.
1) comlist is null
2) dsnyList or AllList is null
It's probably more likely that comlist is null. Could you show me where you construct comlist in your code?
You wrote these lines
wr.violation = violationMap.get(cl.ViolationId__c).Violation__c;
wr.guidance = violationMap.get(cl.ViolationId__c).Guidance_to_Avoid_Violation__c ;
wr.penalty = violationMap.get(cl.ViolationId__c).Penalty__c;
But you are not checking for key in the map.So it would be better if you add IF condition before getting values from the map.
Thanks.
Please let me know if it helps.
this is where I constructed comlist
list<Comliance_Checklist__c> comlist =[select id, Category__c,EventId__c,ViolationId__c,Notes__c,Topic_Discussed__c from Comliance_Checklist__c where EventId__c = : eventId ];
The reason why it works on UAT but doesn't work on production is because the issue is data dependent.
The code worked.
Thank you for the support.
thank you Dilip.