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>
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
let me know if it works<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>