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
vcvvcv 

Issue with referencing a field from related custom object

Hi, I have the classic issue. There are three custom objects (Employees, Productivity, Salaries) which have lookup relationships to each other. I'm using the standard controller "Employees__c" and want to make a form where I access the field Level__c from Productivity__c and Grading__c from Salaries__c.

What's wrong with my __r usage? :)
 
<apex:page standardController="Employees__c">
    <apex:form id="formEmp" >
        
        <apex:pageBlock title="Link employees">
            
            <apex:pageBlockSection columns="1">

            <apex:inputField value="{!Employees__c.FirstName__c}">
                </apex:inputField>

                  <apex:inputField value="{!Employees__c.Productivity__r.Level__c}">
                </apex:inputField>

                         <apex:inputField value="{!Employees__c.Productivity__r.Level__c}">
                </apex:inputField>


                         <apex:inputField value="{!Employees__c.Salaries__r.Grading__c}">
                </apex:inputField>

            </apex:pageBlockSection>

            <!-- buttons -->
            <apex:pageBlockButtons >
                <apex:commandButton id="Save" action="{!Save}" value="Save"/>
                <apex:commandButton id="Cancel" action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            
        </apex:pageBlock>

    </apex:form>
</apex:page>

 
Raj VakatiRaj Vakati
Two issues ... 

You cannt able to save it direcly into the related object from your code 

make changes as below 
 
<apex:inputText value="{!Employees__c.Productivity__r.Level__c}">

implement save logic in apex class
vcvvcv
Hi Raj V,

the code you proposed doesn't work. 

This part works:
<apex:inputText value="{!Employees__c.FirstName__c}">
This doesn't, I get "... apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.":
<apex:inputText value="{!Employees__c.Productivity__r.Level__c}">