保存和新按钮不会清除字段

时间:2016-02-03 17:03:15

标签: button salesforce visualforce apex

我有3个自定义视觉力页面。查看记录,编辑哪些编辑以及创建新记录的新视图。编辑和新建有一个保存和新按钮。当我单击“保存”和“新建”时,我需要一个重定向,一个新记录,以及几个要清除的字段,但所有以前的数据都是通过重定向传输的。

我的顶级代码..

public PageReference saveAndNew() {  

    try {
        // Save the current sObject  
        sController.save();   
        Schema.DescribeSObjectResult describeResult = sController.getRecord().getSObjectType().getDescribe();  
        // Create PageReference for creating a new sObject and add any inbound query string parameters.  
        PageReference pr = new PageReference('/' + describeResult.getKeyPrefix() + '/e?' + queryString);  
        // Don't redirect with the viewstate of the current record.  
        pr.setRedirect(true);  
        eventPackageRevenueBreakdown = new eventPackageRevenueBreakdown__c();
        eventPackageRevenueBreakdown.Name = null;
        eventpackageRevenueBreakdown.AdminIsIncludedInInclusivePrice__c = false;
        return pr;  
    } catch(Exception e) {  
        // Don't redirect if something goes wrong. May be a validation or trigger issue on save.  
        ApexPages.addMessages(e);  
        return null;  
    }  
}

1 个答案:

答案 0 :(得分:0)

我建议您查看Using the transient Keyword。将您不想传输的数据标记为 transient