the code compiles but the page has Attempt to de-reference a null object.I tried system.assertequals so myTeacher and teacherSet is not null but myTea is null. it does not return error and i have no clue what went wrong. (hardcoded selectedSId for testing)

 public void fetchTeacherInfo(){

            selectedSId = 'a0P28000001pOBa';
                for (student__c stud : [Select Id, name, first_name__c, parent__c, teacher_set__c from student__c WHERE Id = : selectedSId]){   
                    teacherSet = stud.teacher_set__c;
                 for (teacher__c myTeacher : [Select Id, name, first_name__c, teacher_set__c, middle_name__c from teacher__c WHERE teacher_set__c = : teacherSet]){

                 if (myTeacher !=  null)

                            //  system.assertequals(myTea + 'test','test');


You need to initialize your set before adding value in it..

In your constructor

myTea = new set<Id>();

after that you can add value in this set


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.