You need to sign in to do that
Don't have an account?
Syed F Raza
Creating List of A Class
Hi All I have the following code
Please advise why I am getting this error.
// I am creating a Class called LClass //This class will have 3 data members //Two of them primitive and one list of this //class public class LClass { public Integer A; public String B; public List<LClass> Llist = new List<LClass>(); //So far this code is saving without any issue on //Developer Console } //Then in Execute Anonymous Window I wrote the following code //I am instantiating the class LClass LC = new LClass(); LC.A=100; LC.B='Myself'; //Now i would like to add this object in the Llist I created in the class. Llist.add(LC); //When i execute this code, it gives me the following error. Variable does not exist: Llist
Please advise why I am getting this error.
First of all, your approach is wrong, you are including the same class as it's child which is a void case.
secondly,
thanks for your response.
Can you please explain on the use of child class as I don't have a child class in this code. I wrote the following code in Execute Anonymous Window:
Hi Raza,
Think of this way.
Llist is a member variable of LClass.
But in the anonymous window, when you have initialised the class with the object LC, Llist is no-where to be seen.
Thus, use LC.Llist.add(LC) instead.