You need to sign in to do that
Don't have an account?
taradyn
0down votefavorite
I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a DisplayProducts class that I've created.
I keep getting a compile error: invalid FK relationship.
I tried but it will only retrieved the first element.
How do I retrieve the child item via the DisplayProducts Class? Any help will be greatly appreciated.
Thank you.
Invalid FK relationship in VF
0down votefavorite
I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a DisplayProducts class that I've created.
public class DisplayProducts { private Product__c products; public DisplayProducts(Product__c item) { this.products = item; } // Properties for use in the Visualforce view public String name { get { return products.Name; } } public String colour { //error here get { return products.Inventorys__r.Colour__c; } } public class Product { public List<DisplayProducts> getProducts() { if(products == null) { products = new List<DisplayProducts>(); for(Product__c item : [Select ProductID__c,Name, Price__c, (SELECT Inventory__c.Size__c, Inventory__c.Colour__c, Inventory__c.Quantity__c FROM Product__c.Inventorys__r) From Product__c WHERE ProductID__c = :prodID]) { products.add(new DisplayProducts(item)); } } return products; } }
I keep getting a compile error: invalid FK relationship.
I tried but it will only retrieved the first element.
products.Inventorys__r[0].Colour__c;
How do I retrieve the child item via the DisplayProducts Class? Any help will be greatly appreciated.
Thank you.
Try with the below code.
All Answers
Replace the below method with the below one
Product__c is the lookup field on child.
It will return you all the chield records.
Try with the below code.