I'm making a Visualforce page where a new Customer__c record is created. Customer__c has a lookup field (recordContact__r) which refers to another custom object: Contact__c.
While the main object record is created fine, the related object record isn't created with this code. What am I missing?
Visualforce
<apex:page showHeader="false" standardController="Customer__c" extensions="ExtendCustomers" sidebar="false" standardstylesheets="false">
<apex:form >
<div>
<apex:commandButton action="{!saveRecord}" value="Save"/>
</div>
<div>
<apex:inputField value="{!Customer__c.Name}" />
<apex:inputField value="{!Customer__c.recordContact__r.Name}" />
<apex:inputField value="{!Customer__c.recordContact__r.Address__c}" />
<apex:inputField value="{!Customer__c.recordContact__r.City__c}" />
<apex:inputField value="{!Customer__c.recordContact__r.State__c}" />
<apex:inputField value="{!Customer__c.recordContact__r.Zip__c} " />
<apex:inputField value="{!Customer__c.Email__c}" />
<apex:inputField value="{!Customer__c.Phone__c}" />
</div>
</apex:form>
</apex:page>
Extension
public with sharing class ExtendCustomers{
public Customer__c newCustomer = new Customer__c();
public ExtendCustomers(ApexPages.StandardController controller) {
this.newCustomer = (Customer__c)controller.getRecord();
}
public PageReference saveRecord() {
insert newCustomer;
}
}