function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dman100Dman100 

clear inputFields after update

How do I clear the inputfields after an update?

 

here is my VF page:

 

<apex:page Controller="AccountMaintenanceController"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Update" rerender="successMsg" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="successMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } }

 

 

I've tried setting the private fields to an empty string, but that did not work.

 

Thanks for any help.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
The problem is that you're rerendering the pageMessages tag instead of the entire form. Set the private fields to null, then rerender the entire form instead (i.e. assign an ID to the form and have the reRender attribute reference the form's ID). In this fashion, you won't have to return a page reference, won't have to add param tags, won't have to do anything funky at all. The problem was merely a "cosmetic" issue by not rerendering the correct portion of the page.

All Answers

WesNolte__cWesNolte__c

Hey

 

Because you're returning null as your pagereference you controller is maintaining the 'session' ie. the state of your controller and all variables is being preserved, try this instead:

 

 

public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); PageReference pr = System.CurrentPage(); pr.setRedirect(true); return pr; }

 

 There is one negative implication here, your page message are not going to show up. As an alternative you might consider attaching a parameter to the pagereference before you return it and use this parm to decide whether to display a message or not.

 

Cheers,

Wes 

 

Dman100Dman100

I tried modifying my method to return the current page reference, but it returned an xml page:

 

<?xml version="1.0" ?> - <html xmlns="http://www.w3.org/1999/xhtml"> - <head> <script src="/faces/a4j/g/3_3_0.GAorg.ajax4jsf.javascript.AjaxScript" type="text/javascript" /> <meta name="Ajax-Update-Ids" content="" /> <title /> </head> - <body> - <span id="ajax-view-state"> <input type="hidden" id="com.salesforce.visualforce.ViewState" name="com.salesforce.visualforce.ViewState" value="0UFzeJ2E1yECx31UQRQloMv8ouwx4qw7WaCyk7dlBt0t6vbTxtcJS25l7KNrrb7rVfuiQB+gIxVJ9hYJ0sT8XCKFY0NdZYziyxUy9j8qWn5VlxjA8h1CHyL8oHzDU2gfyanLQIEpSUasOIZ8Erh++eUoMIHN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A4fuqCRaRvHx+gLo4HHPoJZKsNDDtCeqqp4hm2w2s5jOb9bzcPl8Ch5RG4qiCbZeZPRcIWu92Diyvbj5WPltEa4oXIn47OiYF47TUsKhhEIODMc6KZaxyTwtAFwpn3Eo8TIDEa8ogEyhJ3BbAgd+OT3kCBQlba94UIKjcN98Aiyvu5Salh+iNMKbXtywXEdKVFAJLHAuWgZzc2ijjswF+QtHrYJWM5461Pwq+qvZ5+vcOlgUxoz8qNvhOXQkRsK1xj3GtKcSvHMTP9u7qaqeS/5EFx0gAVCoKCMudtrIyfSNtgHNcHLvGif7RKzk6hgmy6PE8aNkGxcttr2CLUxRibAApSkPOtDOBbJcptUe6ubQBsRGKr074OGHlYKyiZKwJ9JV6tYuwfFpwGIaXn3N8WQoNU+EbE1oKxJuH+njm0TURXJKWJ/9xGa6EoJu6AnRWtdkJxVRkKsP+0AXy++lqneMO3zZSikTqbyiziA3+zjm/GhJkIwscH/0KtiFqgSmQvnJpnKXG8wLKwJwGwl5NbvejdVqyUCnrDhnaECNJ1O6Puog9duHssrb7THgI1b9Lc0HBaTsXViGIBc4YomyV3A688+ab6z5Vi3Xq2rfjwotBhmsek4DisOaavjwOphDXlBtvObgyalSm3Ns5oIrYU4KTjPEi+Ir2K98iqPUu31p+m9ov2JvIk+XW3k6z+VUceUVTN4RVXc9qD+oUYSw84pAk847w1fuZaQfIQzjGVnJdV+L2g9eHLQQrTDzTZDdbmhqW8AkYmcUuf6AF2mk0xc32TBsZH550mCKyv2e7e+DIyuCv7Nn4yiXxdJbdyPIjpr4v4Y4Oj3tOqHbPGHdi47AWt1GcBgye1ZocgvR" /> <input type="hidden" id="com.salesforce.visualforce.ViewStateMAC" name="com.salesforce.visualforce.ViewStateMAC" value="ALnJJ/oYHCs1nQp7niGii4v7S79T" /> <input type="hidden" id="com.salesforce.visualforce.ViewStateCSRF" name="com.salesforce.visualforce.ViewStateCSRF" value="nqn7JQ6TsGoIEtk0wAaXu5E9qlX5MKGhfA5FYlG0x2riGBq2e2JVVWWMnL3Zy1K0wkioJdIqcF9zsGFumUtkfGNwR8STF_wc0XjAKeEhaNYosBaF56rVZVIf0BClq12jKCbzl7kC8pczAP3BACqYEl3WCio=" /> </span> <meta id="Ajax-Response" name="Ajax-Response" content="true" /> </body> </html>

 

Here is the updated method:

 

public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); PageReference pr = new PageReference(System.currentPageReference().getURL()); pr.setRedirect(true); return pr; //return null; }

 

WesNolte__cWesNolte__c

Hey

 

You can either try copying the text I've created in blue(within the code box), and if that doesn't work try:

 

PageReference pr = System.Page.WhateverYourPageNameIs;

pr.setRedirect(true);

return pr;

 

Wes

Dman100Dman100

Thanks Wes,

 

Referencing the apex page name worked and cleared the inputFields.  As you noted, the message no longer displays.  Do you have a code example of passing a parameter in the Page Referecne to display the success message?  I was trying a couple of different ways but have not been successful in getting the message to display.

 

Thanks.

WesNolte__cWesNolte__c

No problem buddy.

 

Unfortunately it becomes quite a manual process after this, eg.

 

Before you return the page reference attach a parm,

 

pr.getParameters().put('msg','0');

 

Then when the page loads fetch this parm, in the constructor maybe,

 

String msg = ApexPage.CurrentPage().getParameters().get('msg');

 

And then you'd have to style a visualforce tag on the page to display it,

 

<apex:outputPanel layout="block" style="...." rendered="{!NOT(ISNULL(msg))}">

  <apex:outputText value="..." />


</apex:outputPanel>

 

Not so neat I know, and if anyone has a smarter way I'm keen to hear it.

 

Wes

sfdcfoxsfdcfox
The problem is that you're rerendering the pageMessages tag instead of the entire form. Set the private fields to null, then rerender the entire form instead (i.e. assign an ID to the form and have the reRender attribute reference the form's ID). In this fashion, you won't have to return a page reference, won't have to add param tags, won't have to do anything funky at all. The problem was merely a "cosmetic" issue by not rerendering the correct portion of the page.
This was selected as the best answer
WesNolte__cWesNolte__c
I do believe the fox is right, doh! Apologies for breezing over the code..
Dman100Dman100

Thanks sfdcfox...I set the private fields to null, set an id for the form tag element and added that value to the re-render attributue on the command button element.  It cleared the fields when the page posts back.  However, I did encounter small issue, the pageMessage in all three actionRegions are displaying.

 

VF page code:

 

<apex:page Controller="AccountMaintenanceController"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form id="AccountMaintenance" > <apex:actionRegion > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, AccountMaintenance" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Update" rerender="UpdateChildAccountsSuccessMsg, AccountMaintenance" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageMessages rendered="true" id="UpdateChildAccountsSuccessMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Account Ownership by State" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountByState}" value="Update" rerender="UpdateOwnerByStateSuccessMsg, AccountMaintenance" status="StateLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateOwnerByStateSuccessMsg" /> <apex:actionStatus id="StateLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to update owner of accounts by selected state" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByState.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="State" for="state" /> <apex:inputField value="{!State.State__c}" id="state" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> </apex:form> </apex:page>

 

controller class code:

 

public class AccountMaintenanceController { private Account acctFrom = new Account(); private Account acctTo = new Account(); private Account acctToByParent = new Account(); private Account parentAcct = new Account(); private Account acctToByState = new Account(); private Account state = new Account(); public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByParent.OwnerId = null; parentAcct.parentId = null; return null; } public PageReference updateAccountByState() { List<Account> accts = [Select Id, OwnerId From Account where state__c =: state.state__c]; List<Account> lst = new List<Account>(); for (Account acct: accts) { acct.OwnerId = acctToByState.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByState.ownerId = null; state.state__c = null; return null; } public PageReference updateAccountsOpportunities() { List<Account> acctsFrom = [Select Id, OwnerId From Account where ownerId =: acctFrom.ownerId]; List<Opportunity> oppys = [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId]; List<Account> acctsToUpdate = new List<Account>(); for (Account acct: acctsFrom) { acct.OwnerId = acctTo.OwnerId; acctsToUpdate.add(acct); } if (acctChkbox) { DbUtil.save(acctsToUpdate); } List<Opportunity> oppysToUpdate = new List<Opportunity>(); for (Opportunity op: oppys) { op.OwnerId = acctTo.ownerId; oppysToUpdate.add(op); } if (oppyChkbox) { DbUtil.save(oppysToUpdate); } List<Opportunity> oppysCommissionSalespersonToUpdate = new List<Opportunity>(); for (Opportunity op: oppys) { op.Commission_Salesperson__c = acctTo.ownerId; oppysCommissionSalespersonToUpdate.add(op); } if (oppyEmailChkbox) { DbUtil.save(oppysCommissionSalespersonToUpdate); } ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Records updated successfully.'); ApexPages.addMessage(msg); acctFrom.ownerId = null; acctTo.ownerId = null; acctChkbox = false; oppyChkbox = false; oppyEmailChkbox = false; return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountFrom() { return acctFrom; } public Account getAccountTo() { return acctTo; } public Boolean acctChkbox { get; set; } public Boolean oppyChkbox { get; set; } public Boolean oppyEmailChkbox { get; set; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } public Account getAccountToByState() { return acctToByState; } public Account getState() { return state; } }

 

 

Thanks.

esepauloesepaulo

Hi!

 

My inglish is very bad, sorry....

 

the problem is solved with the following code

 

public with sharing class ControllerApexVF{
//Create a variable for id url
  String idURL = null;

//Constructor
  public ControllerApexVF(ApexPages.StandardController controller){
      idGasto = controller.getId();
  }
//Method Clear or Reset

  public pagereference Reset(){
    
    PageReference newpage = new PageReference('/apex/yourAPexPage?=');    
    newpage.getParameters().clear();
    newpage.setRedirect(true);
    newpage.getParameters().put('id',idGasto);
    return newpage;
  }
<apex:page standardController="Object__c" extensions="ControllerApexVF">
	<apex:pageBlockButtons location="top" >
                <apex:commandButton value="Clear" action="{!reset}"  rerender="block" status="status" />
	</apex:pageBlockButtons>
</apex:page>

 




}