1

I am trying to display picklist values from a multi select picklist from a related object. I am using a visualforce page and putting this in the record detail.

VF Code:

<apex:page showHeader="false" standardController="ElementsController" >  sidebar="false" standardstylesheets="true"> 
    <apex:pageBlock title="Elements within the Material">
    <apex:outputLabel title="Elements"></apex:outputLabel>
        <apex:actionRegion >
          <apex:pageBlockSection id="Materials" title="Element Information">
    <apex:actionSupport event="onchange" action="{!ElementsConroller}" rerender="Materials, msgs"/>
         <apex:outputField value="{!Requirement__c.Material__c.Elements_within_the_material__c}"/>
        </apex:pageBlockSection>
      </apex:actionRegion>

    </apex:pageBlock>

</apex:page>

Controller:

public with sharing class ElementsController {

 private ApexPages.StandardController stdCtrl;

 public ElementsController(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }

 public void MaterialPopulate()
 {
  Requirement__c Mat=(Requirement__c) stdCtrl.getRecord();
  Mat.Material__c=[select Material__c.Elements_within_the_material__c, Materials from Requirement__c where id=:Mat.Id];
 }
}

I am getting the following error:

Didn't understand relationship 'Material__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

That error is from the controller. When i append the __r for the reference I get the following error:

Code change:

public void MaterialPopulate()
 {
  Requirement__c Mat=(Requirement__c) stdCtrl.getRecord();

 // code changed                    HERE
  Mat.Material__c=[select Material__r.Elements_within_the_material__c, Materials from Re
quirement__c where id=:Mat.Id];

 }
}

No such column 'Materials' on entity 'Requirement__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Can anyone help me out?

1 Answer 1

1

Related object can be accessed using __r in Salesforce which is missing in your code and error is stating the same. So your visualforce page code will be like this

<apex:page showHeader="false" standardController="Requirement__c" extension="ElementsController">  sidebar="false" standardstylesheets="true"> 
    <apex:pageBlock title="Elements within the Material">
    <apex:outputLabel title="Elements"></apex:outputLabel>
        <apex:actionRegion >
          <apex:pageBlockSection id="Materials" title="Element Information">
    <apex:actionSupport event="onchange" action="{!ElementsConroller}" rerender="Materials, msgs"/>
         <apex:outputField value="{!Requirement__c.Material__r.Elements_within_the_material__c}"/>
        </apex:pageBlockSection>
      </apex:actionRegion>

    </apex:pageBlock>

</apex:page>

and you can remove apex class and you can directly use that using standard controller="Requiredment__c"

2
  • I can also seem some other issue with your code. you are calling ElementsController on action. but you don't have any method name defined. so you need to fix that. if you are using any custom controller
    – Himanshu
    Feb 11, 2016 at 19:39
  • Thanks for the answer. I removed the actionSupport tags and it works fine. Is there a way to make the width of the field larger? I put this in its own section on the layout so I can use the space. I tried adjusting the columns and all but that made no impact on the field width.
    – Jason
    Feb 11, 2016 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .