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

System.NullPointerException / Not sure why variable is being considered null
Hi EVeryone,
Stumped on why i keep getting the following error when testing my code block: System.NullPointerException: Attempt to de-reference a null object
I understand the reason for the error, but cannot seem to figure out why the code is throwing it. the Feedback object should be initialized and be able to be added to the feedbackList.
Appreciate the help!
Stumped on why i keep getting the following error when testing my code block: System.NullPointerException: Attempt to de-reference a null object
I understand the reason for the error, but cannot seem to figure out why the code is throwing it. the Feedback object should be initialized and be able to be added to the feedbackList.
Appreciate the help!
String d = 'a0G190000015uMg'; //for testing //containers for querys Deliverable__c deliverable; List<Feedback_Survey_Question__c> questionList; List<Feedback_Responses__c> responseList; List<Feedback__c> feedbackList; List<Approver__c> approverList; //query db for lists deliverable = [SELECT id, type__c, milestone__c, Number_of_Concepts__c, Status__c FROM Deliverable__c WHERE id = :d]; approverList = [SELECT id, name, Approver__c, Approver_Role__c FROM Approver__c WHERE Deliverable__r.id = :d]; //assign pieces of delvierable decimal concepts = deliverable.Number_of_Concepts__c; string milestone = deliverable.milestone__c; System.debug(deliverable); System.debug(concepts); System.debug(milestone); for (Integer i = 1; i <= concepts; i++){ for (Approver__c a : approverList) { String role = a.Approver_Role__c; String aid = a.id; Feedback__c Feedback = new Feedback__c(); Feedback.Name = 'Concept ' + i; Feedback.Deliverable__c = d; Feedback.Approver__c = aid; feedbackList.add(Feedback); //ERROR BEING THROWN HERE } }
You forgot to initialize a list of feedback. Kindly add below line, just before for loop.
feedbackList = List<Feedback__c>();
Regards
Mohit Bansal
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
All Answers
You forgot to initialize a list of feedback. Kindly add below line, just before for loop.
feedbackList = List<Feedback__c>();
Regards
Mohit Bansal
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
FYi..I have added the check.
String d = 'a0G190000015uMg'; //for testing
//containers for querys
Deliverable__c deliverable;
List<Feedback_Survey_Question__c> questionList;
List<Feedback_Responses__c> responseList;
List<Feedback__c> feedbackList;
List<Approver__c> approverList;
//query db for lists
deliverable = [SELECT id, type__c, milestone__c, Number_of_Concepts__c, Status__c FROM Deliverable__c WHERE id = :d];
approverList = [SELECT id, name, Approver__c, Approver_Role__c FROM Approver__c WHERE Deliverable__r.id = :d];
//assign pieces of delvierable
decimal concepts = deliverable.Number_of_Concepts__c;
string milestone = deliverable.milestone__c;
System.debug(deliverable);
System.debug(concepts);
System.debug(milestone);
for (Integer i = 1; i <= concepts; i++){
if(approverList.size()>0){ //added The check.
for (Approver__c a : approverList) {
String role = a.Approver_Role__c;
String aid = a.id;
Feedback__c Feedback = new Feedback__c();
Feedback.Name = 'Concept ' + i;
Feedback.Deliverable__c = d;
Feedback.Approver__c = aid;
feedbackList.add(Feedback); //ERROR BEING THROWN HERE
}
}
}