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
PawelWozniakPawelWozniak 

How to display fileds from two objects on one VS page?

I have page which use standard controller of Order__c with extension:

<apex:page standardController="Order__c" extensions="newOrderController" />

 I am able to display fields from Order__c:

 <apex:inputField label="Variant" value="{!Order__c.type__c}"/>

 

 on the same page want to place fields from EndUser__c object like that:

 

<apex:inputField label="Phone" value="{!End_User__c.phone__c}"/>

 it cause an error:  Error: Unknown property 'Order__cStandardController.End_User__c

 

So I added in controller:

 

sObject endUserObj = new End_User__c(); //End User Object

 

 and trying to acces fields of variable which hold an object:

 

<apex:inputField label="Phone" value="{!endUserObj.phone__c}"/>

 but still getting:

 

Error: Unknown property 'Order__cStandardController.cmEndUserObj' 

 

Tried to use this get and set methods:

    public sObject getEndUserObj () {
        return endUserObj;
    }
    
    public void setEndUserObj (sObject o) {
        this.endUserObj = o;
    }

 

but then getting error:

Error: Read access denied for {0}  

 
What kind of getters and setters should I use? 



 

Best Answer chosen by Admin (Salesforce Developers) 
PawelWozniakPawelWozniak

Thanks to Prasanna__d for tip. 

I found best solution which is just one line:

public End_User__c endUserObj {get; set;}

 

 Thats all, it contains standards get and set methods so no need to write own. Public modificator is mandatory without it will not work.

 

Now I can acces my object in VS by:

<apex:inputField label="Phone" value="{!endUserObj.phone__c}"/> 

 

 

All Answers

_Prasu__Prasu_

Instead of 

sObject endUserObj = new End_User__c();
Try End_User__c endUserObj = new End_User__c();
PawelWozniakPawelWozniak

Thanks to Prasanna__d for tip. 

I found best solution which is just one line:

public End_User__c endUserObj {get; set;}

 

 Thats all, it contains standards get and set methods so no need to write own. Public modificator is mandatory without it will not work.

 

Now I can acces my object in VS by:

<apex:inputField label="Phone" value="{!endUserObj.phone__c}"/> 

 

 

This was selected as the best answer