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
Phonk64Phonk64 

SObject row was retrieved via SOQL without querying the requested field

 Hi,  I am getting the error "SObject row was retrieved via SOQL without querying the requested field: Conference__c.Technology_Types__c.  Class.SimilarConferencesController.: line 7, column 76 External entry point " when I try to launch my Visualforce page.

Here is my controller code:

 

public class SimilarConferencesController {

private final String conf_type;

public SimilarConferencesController() {
conf_type = [select id, name from Conference__c where id =
:ApexPages.currentPage().getParameters().get('id')].Technology_Types__c;


}



public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select id,name from Conference__c where Technology_Types__c = :conf_type]));
}
return setCon;
}
set;
}
public List<Conference__c> getSimilar() {
return (List<Conference__c>) setCon.getRecords();
}


}

 Here is the visualforce code just in case:

 

 

<apex:page controller="SimilarConferencesController" title="Conferences Like Me">

<apex:pageBlock title="Similar Conferences">
<apex:pageBlockTable value="{!similar}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageBlockTable>

</apex:pageBlock>

</apex:page>

 

 

 

 I've followed the API's examples and I can't figure out what the actual problem is.  I found similar posts, but they didn't help me out very much.  Can anyone shed light on this?  I'm just trying to query the database to display Conference records whose technology type field match the source conference (its a custom link that triggers the visualforce page).

 

I feel like this is a mistake a lot of beginner's make (I'm on day 2 of APEX developement...).

 

Best Answer chosen by Admin (Salesforce Developers) 
bbrantly1bbrantly1

The error most likely comes from this line:

 

 

conf_type = [select id, name from Conference__c where id = :ApexPages.currentPage().getParameters().get('id')].Technology_Types__c;

 

You are trying to retrive the Technology_Types__c value without including it in your select statement.  You should modify your code to the following:

 

 

conf_type = [select Technology_Types__c, id, name from Conference__c where id = :ApexPages.currentPage().getParameters().get('id')][0].Technology_Types__c;

 

Remember that when you use a query inclosed in []'s it will return a list result just like if you use Database.query().  So you must add the "[0]" to ensure you only return one (the first) result when you're storing it to a string.

 

Feel free to write back if you need additional help.

 

 

 

 

All Answers

bbrantly1bbrantly1

The error most likely comes from this line:

 

 

conf_type = [select id, name from Conference__c where id = :ApexPages.currentPage().getParameters().get('id')].Technology_Types__c;

 

You are trying to retrive the Technology_Types__c value without including it in your select statement.  You should modify your code to the following:

 

 

conf_type = [select Technology_Types__c, id, name from Conference__c where id = :ApexPages.currentPage().getParameters().get('id')][0].Technology_Types__c;

 

Remember that when you use a query inclosed in []'s it will return a list result just like if you use Database.query().  So you must add the "[0]" to ensure you only return one (the first) result when you're storing it to a string.

 

Feel free to write back if you need additional help.

 

 

 

 

This was selected as the best answer
Phonk64Phonk64

That worked!  I've been staring at this all day and made such an elementary mistake!  Of course you need to pull the field you want to access!  I'm used to getting Null Pointer Exceptions from other web frameworks that I didn't make the connection.  The error message makes so much sense now :smileytongue: 

 

Thanks a lot.  The second pair of eyes always helps.

Message Edited by Phonk64 on 06-29-2009 06:26 PM
bbrantly1bbrantly1

No worries, it happens pretty often to me when I rewrite queries.

 

if you could please select my response as the  solution, it will help others searching for the same problem.

 

Happy Programming!

andrew_mowatandrew_mowat

I am getting a similar error message and was hoping you might be able to help.

 

I have an Account controller extension, with a method that I'm hoping will return all the events that have happened at an account, or its related accounts.

 

I am getting the following error message:

 

SObject row was retrieved via SOQL without querying the requested field: Account.unique_id__c

 

My method:

 

 public List<Event> getMeetings() {

 

set<ID> fullAcctIds = new Set<ID>();

 

for(Account acc1 : [select id from account where unique_id__c =: acct.unique_id__c]) {

fullAcctIds.add(acc1.id);

}

for(Account acc2 : [select id, parent_unique_id__c from account where parent_unique_id__c =: acct.parent_unique_id__c]) {

fullAcctIds.add(acc2.id);

}

for(Account acc3 : [select id, head_office_unique_id__c from account where head_office_unique_id__c =: acct.head_office_unique_id__c]) {

fullAcctIds.add(acc3.id);

}

 

meetings = [select id from event where accountId in :fullAcctIds];

 

return meetings;

}

 

Any help would be greatly appreciated!

 

Cheers,

Andrew