+ Start a Discussion
StaciStaci 

After Save, blank out fields

I have the following code, the last section has fields to add more licenses to the list.  After Save, I'd like the fields to return to blank or None, or whatever they were before the use filled them in.  Right now, if I F5, it adds another license to the list.  If I try to change the values and click save it errors, and then adds the previous options to the list again.
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" sidebar="false">
<!------------------------------------------------------------------------------------------------------>
<!--Based on option chosen for License Type, will show description of that license type-->
<apex:pageBlock title="License Definitions">
<apex:form id="theForm">
<apex:pageBlockSection columns="1">
<apex:selectList label="Please select a License Type"  value="{!discountScheduleID}" size="1" >
   <apex:actionSupport event="onchange" action="{!displayDescription}" rerender="description"/>
   <apex:selectOptions value="{!schedules}" />
</apex:selectList> 

<apex:outputText label="Description" id="description" value="{!OutPutString}"/>

<br></br><br></br><br></br><br></br>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current Licenses">
<apex:pageBlockSection columns="1">

<apex:pageBlockTable value="{!LicenseList}" var="ln">

<apex:outputLink value="{!ln.Id}">{!ln.Name}</apex:outputLink>

<apex:column value="{!ln.Org__c}" />
<apex:column value="{!ln.Business_Unit__c}" />
<apex:column value="{!ln.BMS_Code__c}" />
<apex:column value="{!ln.License_Type__c}" />
<apex:column value="{!ln.Monthly_Unit_Price__c}" />
<apex:column headerValue="2016 Starting Amount" value="{!ln.X2016_Starting_Amount__c}" />
<apex:column headerValue="2016 Running License Total" value="{!ln.Running_License_Total__c}" />
<apex:column headerValue="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



<!--------------------------------------------------------------------------------------------------------->
<apex:form id="theForm">
<apex:pageBlock id="blockId" title="2017 License Needs">
<apex:pageBlockSection columns="1">

<td>
<apex:outputText style="font-weight:800" label="Total 2017 Annualized Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!tTotal}" />
</apex:outputText>
</td>
<td>
<apex:outputText style="font-weight:800" label="Total 2017 Estimated Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aTotal}" />
</apex:outputText>
</td>
</apex:pageBlockSection>

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17}" var="ln17">

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == ln17.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == ln17.id}"/>
</apex:column> 

<apex:column value="{!ln17.Org__c}" />

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17.BMS_Code__c}" rendered="{!tobeEdited == ln17.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17.BMS_Code__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column value="{!ln17.License_Type__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 

<apex:column value="{!ln17.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column headerValue="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<apex:pageBlock title="New Licenses Needed for 2017" id="newblock">

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column HeaderValue="Org">
<apex:inputField value="{!wrapper.lic.Org__c}" />
</apex:column>

<apex:column HeaderValue="Business Unit">
<apex:inputField value="{!wrapper.lic.Business_Unit__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type__c}"  />
</apex:column>

<apex:column HeaderValue="BU Agrees to Pay">
<apex:inputField value="{!wrapper.lic.BU_Agrees_to_Pay__c}" />
</apex:column>

<apex:column HeaderValue="2017 Number Needed">
<apex:inputField value="{!wrapper.lic.X2017_Total_Needed__c}" onclick=""/>
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}" />

<!--------------------------------------------------------------------------------------------------->

        
</apex:form>

<!--------------------------------------------------------------------------------------------------------->
</apex:page>
public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}
public decimal aTotal{get;set;}
public decimal tTotal{get;set;}
public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public LicenseList(ApexPages.StandardSetController controller) { 
currentuser=new User(); 
currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; 
this.ln = (License_Numbers__c)controller.getRecord(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

//------------------------------------------------------------------------------------

public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c];
       

return lntypes16; 
} 


//-----------------------------------------------------------------------------
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();
 
public List <License_Numbers__c> getLicenseList17(){ 

selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017' ORDER BY Order_Number__c, License_Type__c]; 
 aTotal = 0.0;
 tTotal = 0.0;       
        for(License_Numbers__c a:selectedTypes){
                aTotal = aTotal + a.X2017_Cost__c; 
                tTotal = tTotal + a.X2017_Subtotal__c;  
        }
return selectedTypes; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
       License_Numbers__c lic = wrap.lic;
       lic.RecordTypeID = '012Q00000009F7P';
       lic.License_Year__c = '2017';
       addlic.add(wrap.lic);
    }
        
    insert addlic;
    //addlic = null;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
         
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
            
    }
}  //There's a lot more code here for the Schedules part - doesn't pertain to my problem
}

User-added image
 
SFDC RJSFDC RJ
Hi,
To blank fields after saving the record then you have to use pagereference method that would return you to the input page and all the previous values of fields will be blank or none. 
Thanks
StaciStaci
@Rahul Jha 53

So this line that I already have isn't right?

return new PageReference('/apex/LicenseSummaryHomePage');

 
SFDC RJSFDC RJ
@staci
Is it returning you to the new edit page ?
StaciStaci
@Rahul Jha 53

It returns to the same page.  The fields are always editable, which is what I want.  On save, I want them to stay editable, just blank out or go back to --None--
SFDC RJSFDC RJ
@staci
After insert use,
License_Numbers__c lic = new License_Numbers__c();
This may help .
Thanks
StaciStaci
@SFDC RJ
That didn't work :(  any other suggestions?
SFDC RJSFDC RJ
Hi, 
If you are taking about last save button, then you are using a standard save funtionality not from the paex class that is the reason after saving the record it is not returning blank or null values in the fields.
Thanks.
StaciStaci
@SFDC RJ
I changed the class to this:
public List<License_Numbers__c> addlic {get; set;} 
  

public PageReference addsave()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
       License_Numbers__c lic = wrap.lic;
       lic.RecordTypeID = '012Q00000009F7P';
       lic.License_Year__c = '2017';
       addlic.add(wrap.lic);
    }
        
    insert addlic;
      
    return new PageReference('/apex/LicenseSummaryHomePage');
    
         
}

and vf page line to this: 
<apex:commandButton value="Save" action="{!addsave}" />

The behaviour is still the same