Skip to main content
added 646 characters in body
Source Link
taradyn
  • 93
  • 1
  • 12

I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a 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; }
//products.Inventorys__r[0].Colour__c; --> only retrive the first element, dosen't seems to work
    }

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;
}

}

However I keep getting a compile error: invalid FK relationship. Why is that so?

When I retrieve the object using SOQL statement it works perfectly.

Select Name,  (SELECT Inventory__c.Colour__c FROM Product__c.Inventorys__r)  From Product__c];

but why it doesn't work in the Display Class? Thank you.

I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a 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; }

    }

However I keep getting a compile error: invalid FK relationship. Why is that so?

When I retrieve the object using SOQL statement it works perfectly.

Select Name,  (SELECT Inventory__c.Colour__c FROM Product__c.Inventorys__r)  From Product__c];

but why it doesn't work in the Display Class? Thank you.

I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a 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; }
//products.Inventorys__r[0].Colour__c; --> only retrive the first element, dosen't seems to work
    }

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;
}

}

However I keep getting a compile error: invalid FK relationship. Why is that so?

When I retrieve the object using SOQL statement it works perfectly.

Select Name,  (SELECT Inventory__c.Colour__c FROM Product__c.Inventorys__r)  From Product__c];

but why it doesn't work in the Display Class? Thank you.

Tweeted twitter.com/#!/StackSalesforce/status/548126518434877441
Source Link
taradyn
  • 93
  • 1
  • 12

Invalid Foreign Key Relationship when retrieving from class

I've a parent object (Product) and a child (Inventory). I'm trying to retrieve the value of the child object from a 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; }

    }

However I keep getting a compile error: invalid FK relationship. Why is that so?

When I retrieve the object using SOQL statement it works perfectly.

Select Name,  (SELECT Inventory__c.Colour__c FROM Product__c.Inventorys__r)  From Product__c];

but why it doesn't work in the Display Class? Thank you.