新记录页面的 URL 为 {org URL}/{3 个字母对象前缀}/e?"。
您可以按如下方式定义 save 方法,其中 m_sc 是对在其构造函数中传递给扩展的 standardController 的引用:
public Pagereference doSaveAndNew()
{
SObject so = m_sc.getRecord();
upsert so;
string s = '/' + ('' + so.get('Id')).subString(0, 3) + '/e?';
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
return new Pagereference(s);
}
要将控制器用作扩展,请修改其构造函数以将 StandardController 引用作为参数:
public class TimeSheetExtension
{
ApexPages.standardController m_sc = null;
public TimeSheetExtension(ApexPages.standardController sc)
{
m_sc = sc;
}
//etc.
然后只需修改你的<apex:page>
页面中的标记将其作为扩展引用:
<apex:page standardController="Timesheet__c" extensions="TimeSheetExtension">
<apex:form >
<apex:pageMessages />
{!Timesheet__c.Name}
<apex:commandButton action="{!doCancel}" value="Cancel"/>
<apex:commandButton action="{!doSaveAndNew}" value="Save & New"/>
</apex:form>
</apex:page>
请注意,类名中不需要 Extension,我这样做只是为了明智。您不需要修改页面上的任何其他内容即可使用此方法。