salesforce中同一页面上的主项和子项数据输入

salesforce中同一页面上的主项和子项数据输入,salesforce,visualforce,apex,Salesforce,Visualforce,Apex,有谁能帮我告诉我如何在salesforce中为同一页上的主记录和详细记录进行数据输入。 用户不必从母版页移动到子页来填写表单 !!谢谢 我是这样做的 我有一个Visualforce页面,可以保存一个主联系人、最多4个相关联系人以及一个与主联系人相关的自定义对象。我将尝试将代码剥离到这里的要点,因为我所做的很多工作都是保存/复制对其他人没有任何意义的字段。这是Visualforce代码。请注意,我们使用的是带有控制器扩展的标准控制器 <apex:page standardController

有谁能帮我告诉我如何在salesforce中为同一页上的主记录和详细记录进行数据输入。 用户不必从母版页移动到子页来填写表单


!!谢谢

我是这样做的

我有一个Visualforce页面,可以保存一个主联系人、最多4个相关联系人以及一个与主联系人相关的自定义对象。我将尝试将代码剥离到这里的要点,因为我所做的很多工作都是保存/复制对其他人没有任何意义的字段。这是Visualforce代码。请注意,我们使用的是带有控制器扩展的标准控制器

<apex:page standardController="Contact" extensions="ContactEntryPageController">
<apex:form id="FastContactEntryForm">       
<apex:pageBlock title="Fast Contact Entry" mode="edit" id="FCEMainBlock" >           
<apex:outputPanel id="InputSec">                      
<apex:pageBlockSection title="Contact1" id="sc1" columns="2">
<apex:pageBlockSectionItem >
<!-- saveAndBackToEdit is where the related contacts and the child object are saved -->
<apex:commandButton action="{!saveAndBackToEdit}" value="Save" id="theSaveButton1"/><p/>
</apex:pageBlockSectionItem>                      
...

<!-- note how we use "inputField" and "contact.FirstName" for fields in the main object -->         
<apex:pageBlockSectionItem>
First Name:<apex:inputField value="{!contact.FirstName}"/>
</apex:pageBlockSectionItem>
...   
<apex:pageBlockSection title="Primary Guardian" columns="2">
<apex:pageBlockSectionItem >
<!-- note how we use "inputtext" and "PGFirstName" for related contact and child object fields -->
Primary Guardian First Name:<apex:inputtext value="{!PGFirstName}"/>
</apex:pageBlockSectionItem>
下面是saveAndBackToEdit函数的代码大纲,所有工作都在这里进行。请注意,我们获取当前记录,并在保存子对象时使用该记录中的ID

public PageReference saveAndBackToEdit() {
...
//get the main contact being filled out here
ct = (Contact)controller.getRecord();
ct.recordtypeid = '012000000000gKl';  // custom record type  (Salesforce need to be told this)
....
// create child record
Scholar_Program_Application__c sp = new Scholar_Program_Application__c();
sp.Scholar_Name__c = ContactID;
sp.CustomObjectField__c = VFPageFieldForCustomObjectFieldValue;
insert sp;  //save the child object
...
//and finally
PageReference FastContactEditPage = Page.FastContactEntry;  // name of current VF page
FastContactEditPage.setRedirect(true);  //returns us to this page so we can do this again

return FastContactEditPage;
}
public PageReference saveAndBackToEdit() {
...
//get the main contact being filled out here
ct = (Contact)controller.getRecord();
ct.recordtypeid = '012000000000gKl';  // custom record type  (Salesforce need to be told this)
....
// create child record
Scholar_Program_Application__c sp = new Scholar_Program_Application__c();
sp.Scholar_Name__c = ContactID;
sp.CustomObjectField__c = VFPageFieldForCustomObjectFieldValue;
insert sp;  //save the child object
...
//and finally
PageReference FastContactEditPage = Page.FastContactEntry;  // name of current VF page
FastContactEditPage.setRedirect(true);  //returns us to this page so we can do this again

return FastContactEditPage;
}