I have two lists that I am trying to combine to get one list of pets available for adoption (not really, but it's less boring than reality):
List<puppy> puppies = [SELECT Color, Name, Age, PetStores__r.Location, PetStores__r.Section FROM puppy];
List<kitten> kittens = [SELECT Color, Name, Age, PetStores__r.Location, PetStores__r.Section FROM kitten];
I'm running through all results in kitten and casting them to the superior puppy category. But I am getting stuck on figuring out how to add the PetStores fields to the puppy list.
for (kitten k : kittens){
Puppy p = new Puppy();
p.Color = k.Color;
etc
p.PetStores__r.Location = k.PetStores__r.Location; //This is where I am getting lost. Is this possible?
puppies.add(p);
}
The above gives me a de-reference a null object error on the noted line. Is there something easy that I'm missing? Thanks!