+ Start a Discussion

Trying to put a subquery list in a page block but returning error



Getting this extremely annoying issue.


Here is my query:


assets = [SELECT Id, Name, External_Reference__c, Serial_Number__c, UsageEndDate, (SELECT Id, Name, AssetId FROM Entitlements) FROM Asset WHERE Serial_Number__c IN : serialIds ORDER BY UsageEndDate Desc];



I have a nested page block where I want to iterate through the child Entitlements, but I continously get this error:


System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Asset.Entitlements


I can't find any security that is prohibiting me from viewing this list.

Any ideas?


Did you run this soql in the query editor in developer console?



And it returns the subquery list filled with Entitlements.

Is the issue coming from when you open the vf page that runs the controller? Or is it occurring when you try to save the query in the class?

And does your profile have read rights to entitlements?

I'm running as Sys Admin and have full Crud Permission set and no FLS is set on Entitlements.

That query runs on a search command button click, and I get that error as soon as I perform the search.


I tried the following soql below in execute anonymous and it works fine for me:


List <Asset> a = [select id, Name, (Select Id, Name from Entitlements) from Asset];
system.debug('list my assets ======' +a);


Can you try copy and pasting your code block for the query?