Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <apex:page controller="myController">
- <apex:pageblock>
- <apex:pageblockButtons>
- <apex:commandButton value="Save" action="{!saveObjects}"/>
- <apex:pageblockButtons/>
- <apex:pageblocksection>
- <apex:inputfield value="{!myA__c.Name}"/>
- <!-- add any other fields you want for this object -->
- </apex:pageblocksection>
- <apex:pageblocksection>
- <apex:inputfield value="{!myB__C.Color__c}"/>
- <apex:inputfield value="{!myB__C.Location__c}"/>
- </apex:pageblocksection>
- </apex:pageblock>
- </apex:page>
- public class myController{
- public ObjectA__c myA {get;set;}
- public ObjectB__c myB {get;set;}
- public myController(){
- myA = new ObjectA__c();
- myB = new ObjectB__c();
- }
- public void saveObjects(){
- insert myA;
- myB.ObjectA__c = myA.Id;
- insert myB;
- }
- }
- public with sharing class MyExtension
- {
- ApexPages.StandardController sc;
- public ObjectB__c objB {get; set;}
- public MyExtension(ApexPages.StandardController sc)
- {
- this.sc = sc;
- objB = new ObjectB__c();
- }
- public ApexPages.PageReference SaveBoth()
- {
- insert objB;
- return sc.Save();
- }
- }
- <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"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement