【问题标题】:Unable to clear the fileds after saving the data using apex code使用 apex 代码保存数据后无法清除字段
【发布时间】:2013-07-04 08:40:05
【问题描述】:
//Apex page
 <apex:page controller="MyController" tabStyle="Account"  showChat="false" >
    <apex:form >
        <apex:pageBlock title="Congratulations  {!$User.FirstName}">
            You belong to Account Name: <apex:inputField value="{!account.name}"/>
          Annual Revenue:  <apex:inputField value="{!account.AnnualRevenue}" required="true"/>
           <apex:commandButton action="{!save}" value="save"/></apex:pageblock>
    </apex:form>
</apex:page>

我的代码已成功将数据保存到我的帐户。但是,在我按下刷新按钮之前,这些字段不会清除

//Apex Class

public class MyController {


    private Account account; public Account getAccount(){
    if(account == null)
    account=new Account();
    return account;
    }
    public PageReference save(){
    insert account;
    return null;
    }
}

My code is saving the data to my account successfully.But,the fields are not clearing until i press refresh button. 

So, anyone can guide me to clear the page after saving my data?

【问题讨论】:

  • 它应该刷新你的页面我看不到问题。但是,您是否尝试使用 apex:commandButton 的 rerender 属性?

标签: salesforce apex-code


【解决方案1】:

因为帐户值在视图状态下仍然可用。 在 pagereference 方法中添加另一行,这应该会有所帮助。像这样:

public PageReference save(){
   insert account;
   account=null;
   return null;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多