0

I am in the process of developing an apex:form that will save two records: Recipient__c and Scholarship_Award__c.

I need to create a custom controller to save new records for both objects on the same VF page. The trouble is the Recipient__c record will need to be saved first following the insertion of Scholarship_Award__c because it references Recipient__c as the parent in a master-detail relationship.

Ideally, the end-user will input the fields of recipient__c, and scholarship_award__c and two records will be saved: a new recipient, and a new scholarship with that recipient as the parent.

How can I go about developing this?

  • 1
    You can do multiple DML statements in your controller, so you would insert your Recipient record first. The record Id will be immediately available to you after the insert, so you can use it insert your related records. See documentation for an example. – David Cheng Sep 19 at 22:18
  • Thanks. However in creating a wizard it is multiple VF pages and instead I need all the fields to be on the same page - the insert in the class still works fine in a single page? – patriciajlim Sep 20 at 1:17
  • Yes. Note that the example is still a single VF page even though there are various conditional sections on it. – David Cheng Sep 20 at 18:03

Your Answer

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

Browse other questions tagged or ask your own question.