Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
error

We made a wrong turn. Try again.

I have two objects Speaker__c, Session__c. I want to create a single VF page which will includes fields from both objects. VF page will have inputField / inputText type of field. The class through error: Initial terms of field expression must be a concrete sObject: List

VF code through the error: Unknown property 'VFpageName.Session__c'

If I dont initiate objects with List<>, apex class will be fine, but VF page shows same error. How to fix this?

My code: 

Class 

public class SingleVFPagePullDataFromMultipleObjects {

// MVC concept to data binding in VF page & controller

public List<Speaker__c> objectSpeaker {get; set;}

public List<Session__c> objectSession {get; set;}

//define the function

public SingleVFPagePullDataFromMultipleObjects(){

// Initiate objects

List<Speaker__c> objectSpeaker = new List<Speaker__c>();

List<Session__c> objectSession = new List<Session__c>();

}

// Save button

public void save()

{

try

{

insert objectSpeaker;

objectSession.Speaker_Name__c = objectSpeaker.id;

insert objectSession;

}

catch(Exception ex)

{

System.debug('\n\nException ='+ex.getMessage()+'\n\n');

}

}

public void cancel(){}

}

VF

<apex:page controller="SingleVFPagePullDataFromMultipleObjects" >

<apex:form>

<apex:pageBlock>

<apex:pageBlockSection>

<apex:inputText value="{!Session__c.Session_Date__c }" />

<apex:inputText value="{!Session__c.Description__c }" />

<apex:inputText value="{!Session__c.Level__c }" />

<apex:inputText value="{!Speaker__c.Last_Name__c }" />

<apex:inputText value="{!Speaker__c.Bio__c }" />

</apex:pageBlockSection>

<apex:pageBlockButtons >

<apex:commandButton action="{!save}" value="Save"/>

<apex:commandButton action="{!cancel}" value="Cancel"/>

</apex:pageBlockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

 
5 answers
  1. Oct 24, 2016, 9:25 PM
    You cannot access Session__c directly in your visualforce page as you are using custom controller. You have to use variable name objectSession. Please make sure your visualforce page is updated with this code 

     

    <apex:page controller="SingleVFPagePullDataFromMultipleObjects" >

    <apex:form>

    <apex:pageBlock>

    <apex:pageBlockSection>

    <apex:inputText value="{!objectSession.Session_Date__c }" />

    <apex:inputText value="{!objectSession.Description__c }" />

    <apex:inputText value="{!objectSession.Level__c }" />

    <apex:inputText value="{!objectSpeaker.Last_Name__c }" />

    <apex:inputText value="{!objectSpeaker.Bio__c }" />

    </apex:pageBlockSection>

    <apex:pageBlockButtons >

    <apex:commandButton action="{!save}" value="Save"/>

    <apex:commandButton action="{!cancel}" value="Cancel"/>

    </apex:pageBlockButtons>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    let me know if it works 

     
  2. Oct 25, 2016, 1:42 PM
    Change Visualforce to 

     

    <apex:pageBlockSection>

    <apex:inputField value="{!objectSession.Name }" required="true" />

    <apex:inputField value="{!objectSession.Session_Date__c }" />

    <apex:inputField value="{!objectSpeaker.Last_Name__c }" />

    </apex:pageBlockSection>

     
0/9000