Monday, March 10, 2014

Automatically Save the Record

==========VFPAGE=========================
<apex:page sidebar="false" controller="AutoSave">
 <apex:form id="fm">
    <script>
        window.setTimeout(recursivecall,40000);
        function recursivecall(){
              window.setTimeout(recursivecall,40000);
              autosave();
        }
        function ashok(){
           var BN= document.getElementById("{!$Component.fm.pb.ps.pg.bn}").value;
           var BN1= document.getElementById("{!$Component.fm.pb.ps.pg.ba}").value;
           var BN2= document.getElementById("{!$Component.fm.pb.ps.pg.bp}").value;
           if(BN==''){
             alert('nnr');
           } 
        }
  </script>
  <apex:pageBlock title="AutoSave" id="pb">
  <apex:actionFunction name="autosave" action="{!ASMethod}" status="savestatus" reRender="AS"/>
    <apex:pageBlockSection id="ps">
      <apex:actionStatus id="savestatus">
          <apex:facet name="start"> Auto Saving....<img src="/img/loading.gif"/> </apex:facet>
    </apex:actionStatus>

      <apex:panelGrid onclick="ashok()" id="pg">
        <apex:actionSupport event="onclick"  id="AS"  />
        BOOk name    <apex:inputText value="{!log.name}" id="bn" required="true"/>
             Author  <apex:inputtext value="{!Log.Author__c}" id="BA"/>
             Price   <apex:inputtext value="{!log.Price__c}" id="BP"/>
       </apex:panelGrid>
   
    </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

=================Controller==========================
public with sharing class AutoSave {
 
  public Autosave(){
    log=new book__c();
    
  }
  public book__c log{get;set;}
  public void ASMethod(){
   // insert log;
    log.clear();
    
  }
}

No comments:

Post a Comment