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
WYamWYam 

Getting master information from detail standard controller

Hey there and thank you for reading this.

 

I have a VForce page that uses a standard controller from a detail record.

 

I'm trying to access details of the Master record from this Detail record but I'm having trouble. I've been able to go the other (from master to detail). Here is the code snippet for that:

 

 

<apex:page standardController="Budget__c" showHeader="false" sidebar="false">  
.
.
.
<apex:dataTable value="{!Budget__c.Budget_Products__r}" var="bprod" cellPadding="5" border="1"> 
.
.
.
.


 

 

I can't figure out how to go the other way or whether or not it's even possible:

 

<apex:page standardController="Budget_Product__c" showHeader="false" sidebar="false">
.
.
.
<apex:param value="{!Budget_product__c.Budgets__r.Name}" />
.
.
.

 

This may or may not be clear. Again thank you for your help and any insight you can provide.

 

 

Cheers,

Will

 

 

sfdc guy.ax723sfdc guy.ax723

Will,

This is totally possible. You can go from child up 5 levels.

 

Since your starting at the Child level you can go up to the Master by doing what you have written:

 

Budget_product__c.Budgets__r.Name

 

This is essentially a portion of a SOQL statement used to get the data into the page.

 

If you use the Eclipse IDE you can actually see the statement if you drill open the salesforce.schema and look at the Budget_product__c.

 

If you expand the fields for Budget_product__c, select a few fields then expand the field Budget__c and drill through the DataType, ReferenceTo, Budget__c,Fields and select the Name Field you will see the SOQL statement in the QueryResults Text Box. Part of that statement will look like b.Budget__r.Name where b = Budget_product__c

 

Anyway, that part of the statement should be what you put in the value of your apex:param statement.

 

You could also chage the param to outputText to see what is displayed on the page.

sfdc guy

 

 

WYamWYam

Hey there and thanks for the response.

 

I tried your suggestion and found a few things to try but still running into the error. Here is the relevant code snippet:

 

 

<apex:page standardController="Budget_Product__c" showHeader="false" sidebar="false">
.
.
.
<apex:outputText value="{!Budget_Product__c.Budget__r.Name}" />.
.
.

 

Here is the error:

"Save error: Invalid field Budget__r for SObject Budget_Product__c"

 

 

From the schema browswer, selecting just the "Name" field from the Budget__c object gives me this:

"Select b.Name From Budget__c b"

 

If I drill down and get into the Budget_Product__c object and pull out another field called "Product," I get this:

"Select b.Name, (Select Product__c From Budget_Products__r) From Budget__c b"

 

What's odd about this SOQL query is that it lists all the related budget_products__c with a count of the items within that child. As an example the result set looks like:

 

Budget_Products__r(2)

Budget_Products__r(5)

 

 

I'm not totally sure I even understand the error code but any additional insight you can provide is much appreciated.

 

Thanks,

Will

 

 

 

 

 

 

 

 

sfdc guy.ax723sfdc guy.ax723

Will,

 

From the error you shared, it appears to be trying to save the Budget_r.Name value.

 

So another option for seeing the Master Name value on the Detail record, is to create a formula filed on the detail record called "Budget Name" that is a text value and points to the budget__c.name field.

 

Than you can simply use <apex:outputText value="{!Budget_Product__c.Budget_Name__c}" />  on you page.

 

sfdc guy