使用 Apex / JavaScript 很容易实现:
顶点代码:
// Defining two variables for the both records (case and phone)
public String caseId { get; set; }
public String phoneId { get; set; }
// Defining a boolean to render the JavaScript panel after saving
punlic Boolean redirectNow { get; set; }
public PageReference saverecord(){
// Create a new phone call record;
insert record;
// Now reading a phone record id
phoneId = record.id;
if(createnewcase){
create case;
insert case;
// Now reading a case id
caseId = case.id;
}
// If case and phone are OK -> set this flag to true
redirectNow = true;
// We do not need to return a real page reference
// because we will redirecting with javascript
return null;
}
以及带有 JavaScript 的 Visualforce 页面:
<!-- A command button, that rerenders a panel with JavaScript -->
<apex:commandButton value="Save" action="{!saverecord}" reRender="doAfterSave"/>
<!-- This panel renders only after you will save the new records -->
<apex:outputPanel id="doAfterSave">
<apex:outputPanel rendered="{!redirectNow}">
<script>
// First reading the id's
var newCaseId = '{!caseId}';
var newPhoneId = '{!phoneId}';
if(newCaseId != '' && newPhoneId != '')
{
// Now opening a new window with case in edit mode
window.open('/' + newCaseId + '/e');
// And then redirecting the main page to the new phone record
window.location = '/' + phoneId;
}
</script>
</apex:outputPanel>
</apex:outputPanel>