Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <apex:page controller="myController">
  2. <apex:pageblock>
  3. <apex:pageblockButtons>
  4. <apex:commandButton value="Save" action="{!saveObjects}"/>
  5. <apex:pageblockButtons/>
  6. <apex:pageblocksection>
  7. <apex:inputfield value="{!myA__c.Name}"/>
  8. <!-- add any other fields you want for this object -->
  9. </apex:pageblocksection>
  10.  
  11. <apex:pageblocksection>
  12. <apex:inputfield value="{!myB__C.Color__c}"/>
  13. <apex:inputfield value="{!myB__C.Location__c}"/>
  14. </apex:pageblocksection>
  15.  
  16. </apex:pageblock>
  17. </apex:page>
  18.  
  19. public class myController{
  20.  
  21. public ObjectA__c myA {get;set;}
  22. public ObjectB__c myB {get;set;}
  23.  
  24. public myController(){
  25. myA = new ObjectA__c();
  26. myB = new ObjectB__c();
  27. }
  28.  
  29. public void saveObjects(){
  30. insert myA;
  31. myB.ObjectA__c = myA.Id;
  32. insert myB;
  33. }
  34.  
  35. }
  36.  
  37. public with sharing class MyExtension
  38. {
  39. ApexPages.StandardController sc;
  40. public ObjectB__c objB {get; set;}
  41.  
  42. public MyExtension(ApexPages.StandardController sc)
  43. {
  44. this.sc = sc;
  45. objB = new ObjectB__c();
  46. }
  47.  
  48. public ApexPages.PageReference SaveBoth()
  49. {
  50. insert objB;
  51. return sc.Save();
  52. }
  53. }
  54.  
  55. <apex:page standardController="ObjectA__c" extensions="MyExtension">
  56. <!-- snip -->
  57. <apex:inputField value="{!ObjectA__c.Name}"/>
  58. <apex:inputField value="{!objB.Name}"/>
  59. <apex:commandButton action="{!SaveBoth}" value="Save"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement