You need to sign in to do that
Don't have an account?
SOQL References
Hi Everyone, ive got some trouble with the SOQL References.
Error Code:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Order__c.Legs__r Class.PurchaseRequestController.count: line 24, column 33 Class.PurchaseRequestController.getCount: line 4, column 28 External entry point
my syntax: (ive marked the affected lines red)
List<Integer> out = new List<Integer>();
for(Order__c ord : [select Name,Algorithm__c,ExpireDate__c,Legs__c,Slab__c,Screw__c,
Quantity__c from Order__c])
{
Integer quant = (ord.Quantity__c).scale();
out[Integer.valueOf(ord.Legs__r.Id)] += quant;
out[Integer.valueOf(ord.Slab__r.Id)] += quant;
out[Integer.valueOf(ord.Screw__c)] += quant;
}
some solutions?
You need to include the fields you're tring to access in the query (e.g. add legs__r.id and slab__r.id to the query, or switch the other code to use legs__c / slab__c)
your other problem is that Id fields are strings, so Integer.ValueOf(and Id String) isn't going to do much useful.
Not exactly sure what you are trying to accomplish here. Are you trying to total up (ie COUNT()) the total number of Legs, Slabs, and Screws? Or are you trying to sum up something more complicated?
In any case, you don't have to use a __r.Id syntax on a relationship, you can simply use the __c field itself.
hi, thanks for your help,
but I've a problem further, how do I transform a String into an Integer in the Apex Code?
out[Integer.valueOf(ord.Legs__r.ID)] += quant;
maybe someone can expain me