function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
slinslin 

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?

 

SuperfellSuperfell

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. 

 

IanZepp-ISVIanZepp-ISV

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.

cjarliecjarlie

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

 

 

Message Edited by cjarlie on 11-19-2009 08:22 AM
SuperfellSuperfell
What integer are you expecting to get from a string like a06300000008Yo0AAE ?
cjarliecjarlie
ok, it's look like the content is the reference, how can i get the value of the field ID?