[SalesForce] Updating fields from multiple objects on a single visualforce page

I'm trying to create a single visualforce page to update existing records on related custom objects. I've reviewed and experimented with several of the examples on the Stack Exchange but no luck. Most of the examples seem to be for creating new records. I need to show fields from both records, allow the user to make changes and then save the changes.

ObjectA – Job Order
ObjectB – Job Applicant (Job Applicant is unique and there are multiple applicants for every Job. )

A button from the Job Applicant Page will open the VisualForce Page.

apex:inputfield value="{!ObjectA.Stage__c}"<br>
apex:inputfield value="{!ObjectB.Status__c}"

I'm a 3 year Admin, 2 months into Visualforce and just starting Apex Controllers/Extensions.
Examples are appreciated.

Thanks,
Ed

Updated Code below

I leveraged this from LaceySnr Visualforce – Display fields from multiple objects

Here is my code… I'm still getting an error when saving the VF Page
Error: Unknown property 'AVTRRT__Job_Applicant__cStandardController.AVTRRT__Job__c'

Apex Class

public with sharing class SaveExtension
{
    ApexPages.StandardController sc;
    public AVTRRT__Job__c objBJob {get; set;}

    public SaveExtension(ApexPages.StandardController sc)
    {
        this.sc = sc;
        objBJob = new AVTRRT__Job__c();
    }

    public ApexPages.PageReference SaveBoth()
    {
        insert objBJob;
        return sc.Save();
    }
}

VF Page – I've removed everything but the essentials.
It works fine with the filed from the StandardController. I just can't add a field from the other object.

<apex:page StandardController="AVTRRT__Job_Applicant__c" extensions="SaveExtension">
<apex:form >
  <apex:pageblock mode="edit">
       <apex:inputField value="{!AVTRRT__Job_Applicant__c.AVTRRT__Stage__c}" />
       <apex:inputField value="{!AVTRRT__Job__c.Job_Type__c}" />
       <apex:CommandButton action="{!saveboth}" value="Save"/>
  </apex:pageblock>
</apex:form> 
</apex:page>

Thanks for any help!

Best Answer

Ed - Two excellent doc references for you to learn from --

1) http://www.developerforce.com/guides/Visualforce_in_Practice.pdf and

2) https://www.packtpub.com/application-development/visualforce-development-cookbook

both are superb.

You have a conceptual issue in your example in that a VF page is associated with a controller (standard, standard w/ extensions, or custom) and the merge field references have to be to objects known to that controller. So, if you literally want to refer to {!ObjectA.xxx} and {!ObjectB.xxx} then the page's controller has to have either public getMethods or public getters for these specific objects. A page with standardController="ObjectA" has implicit reference to ObjectA's fields and these can be updated. But if you don't have an extension class or go the full custom controller route, ObjectB is unknown

Related Topic