3

I have a custom object called Technology__c and join object called AccountTechnologies which is a join object between Account and Technology__c .So AccountTechnologies has a master detail relationship from both sides. I have added a count__c roll-up summary field in the Technology__c to get the count But when i access it in the visual force page I get the following error

      System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Technology__c.count__c 

The following is the visualforce page code

      <apex:pageBlockTable title="Technologies" value="{!AllTechnologies}"
                var="t">
                <apex:column value="{!t.Name}" headerValue="Technologies" />
                <apex:column value="{!t.count__c}" headerValue="Count" width="20%">

                </apex:column>        
            </apex:pageBlockTable>
yatish mehta
  • 905
  • 1
  • 10
  • 25
  • Are you using the standard controller for the Visualforce page or a custom controller (or extension)? – Matt K Jan 25 '12 at 14:57

1 Answers1

4

You'll need to add the Count__c field to your query in your custom controller.

-- Edit --

If you're querying off of Technologies, the query would look like this:
[Select Id, Name, Count__c From Technology__c];

If you're querying off of a junction object, you would need to query the relationship using a subquery. You can check the Technology or AccountTechnologies object definition (App Setup > Create > Objects) and click the Master-Detail field to find the Child Relationship Name. Add an __r to that relationship name to find what object to subquery from.

To get the Technology__r values into another object you would use the getSObjects() method on the Account. This documentation has a great example at the bottom.

Also, check the custom controller documentation for more information.

Matt K
  • 7,207
  • 5
  • 39
  • 60
  • but it is column and the Technology keeps changing. how to pass that to a customcontroller so that it can be seen in VF – yatish mehta Jan 25 '12 at 15:15
  • The var t needs to passed to the method in the controller and then be returned to VF to display the count. i dont know how to pass the param t to the controller and process it so that the value is shown in the column – yatish mehta Jan 25 '12 at 15:21
  • how do i pass var t to the controller ..sorry i am a newbie in salesforce – yatish mehta Jan 25 '12 at 15:39
  • I edited the answer above adding a description of how to sub-query for the Technology object from Account. Between the Custom Controller documentation and the dynamic SOQL documentation, you should be all set. – Matt K Jan 25 '12 at 15:41
  • Var `t` is set by the `` it doesn't need to be passed. It's a single instance of (or one record from) `Technologies`. – Matt K Jan 25 '12 at 15:43
  • But the roll-up summary field `count__c` keeps the count of the children it has in the join table so y does technology__c.count__c not work – yatish mehta Jan 25 '12 at 15:48
  • how do i access Var `t` in my controller? – yatish mehta Jan 25 '12 at 15:49
  • Is `Count__c` on Account or Technology__c? Are you trying to count the number of Technology records? Var `t` is not accessible in the controller; you would need to look at the Technologies (or Technology__r) list. – Matt K Jan 25 '12 at 15:54
  • I think I finally understand your question. I misunderstood the part about having an object between Account and Technology. Do multiple Accounts need to be related to multiple Technologies? – Matt K Jan 25 '12 at 16:01
  • `count__C` in on technology__c. and AccountsTechnologiesAssociation is the join table which with columns ChildofAccount and ChildofTechnology {master detail from both side} – yatish mehta Jan 25 '12 at 16:01
  • ya a many to many relationship which is stored in AccountsTechnologiesAssociation__c – yatish mehta Jan 25 '12 at 16:02
  • And, in the Visualforce page you want to display all Technologies for a specific Account, or all Accounts and all Technologies? – Matt K Jan 25 '12 at 16:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7039/discussion-between-matthew-keefe-and-yatish-mehta) – Matt K Jan 25 '12 at 16:06