2

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!

  • Making the parent (Job Order) and child (Job Applicant) objects both editable where there can be multiple applicants is a little unusual as the change to the order made for one applicant will appear for all other applicants and that may not be understood by your users. – Keith C Nov 23 '14 at 13:09
  • I have a small user base and putting both objects on the same screen allow them significant efficiencies. Today they have to bounce between objects to make simple updates. – Ed L Nov 23 '14 at 15:45
  • OK your call. On the code formatting, when editing select the code then click the 101010 button. Or you can manually indent by 4. – Keith C Nov 23 '14 at 16:55
  • Thanks Keith C! Found my issue. Added the answer to post. Just posted another questions. Thanks for the hint on updating code. – Ed L Nov 23 '14 at 17:32
3

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

  • I have the Packtpub Visualforce Developer’s guide. Skimming the pdf now. Great stuff. Love drinking from the fire hose! I've already built a vf page with a standard controller that my users love. – Ed L Nov 23 '14 at 15:48
0

Did you tried

<apex:page standardController="ObjectA__c" extensions="ObjectB__c">

to access both object fields? maybe extend the extension with your controller as well?

  • extensions= has to be a classname, not an object name – cropredy Nov 23 '14 at 1:15
  • That's what I'm working towards. I copied my code to the original post. I'd appreciate any input. – Ed L Nov 23 '14 at 15:49
  • @crop1645 - I figured it out and posted the answer here. Thanks! – Ed L Nov 23 '14 at 17:34
0

I figured it out.... Maybe a moderator can post this back to LaceySnr answer Visualforce - Display fields from multiple objects

(I need more reputation points to add comments)

Here is what he put.

 <apex:page standardController="ObjectA__c" extensions="MyExtension">
        <!-- snip -->
        <apex:inputField value="{!ObjectA__c.Name}"/>
        <apex:inputField value="{!ObjectB__c.Name}"/>
        <apex:commandButton action="{!SaveBoth}" value="Save"/>

Here is what works. The objB instead of the actual Object.

<apex:page standardController="ObjectA__c" extensions="MyExtension">
        <!-- snip -->
        <apex:inputField value="{!ObjectA__c.Name}"/>
        <apex:inputField value="{!objB.Name}"/>
        <apex:commandButton action="{!SaveBoth}" value="Save"/>

This post can be deleted. :) Now on to my next question. Learning a lot from Stack Exchange! P.S. I finally figured out how to show my code... preformatted text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.