VF Page Basics 2

standard save

  1. <apex:page standardController="Account" extensions="StdToCustomCls">
  2.      <apex:form >
  3.          <apex:sectionheader title="Home" subtitle="Account Edit"/>
  4.          <apex:pageBlock >
  5.              <apex:pageBlockSection columns="1">
  6.                  <apex:inputfield value="{!Account.Name}"/>
  7.                  <apex:inputfield value="{!Account.Phone}"/>
  8.              </apex:pageBlockSection>
  9.              <apex:commandButton value="Save" style="margin-left:20%;" action="{!dosave}"/>
  10.              
  11.          </apex:pageBlock>
  12.      </apex:form>
  13. </apex:page>

  14. <!--   
  15. Standard Save Button
  16. <apex:commandButton value="Save" action="{!Save}"/>
  17. -->
  1. public with sharing class StdToCustomCls {

  2.     public ApexPages.StandardController acc;
  3.    
  4.    public StdToCustomCls(ApexPages.StandardController controller) {
  5.         acc = controller;
  6.     }
  7.     
  8.     public pagereference dosave(){
  9.         acc.save();
  10.         return (new pagereference('/apex/stdsave').setredirect(true)); //setredirect clears the viewstate values of the object.
  11.     }
  12. }

Custom Save

  1. <apex:page controller="CustomSaveCls">
  2.     <apex:form >
  3.         <apex:pageBlock >
  4.             <apex:pageBlockSection columns="1">
  5.                 <apex:inputfield value="{!objA.Name}"/>
  6.                 <apex:inputfield value="{!objA.Phone}"/>
  7.             </apex:pageBlockSection>
  8.             <apex:commandButton value="Save" action="{!doSave}" style="margin-left:20%;"/>
  9.         </apex:pageBlock>
  10.     </apex:form>
  11. </apex:page>
  1. public with sharing class CustomSaveCls {

  2.     public PageReference doSave() {
  3.         Insert objA;
  4.         return (new pagereference('/apex/customsave').setredirect(true));
  5.     }

  6.     public Account objA{get;set;}
  7.     public CustomSaveCls(){
  8.         objA = new Account();
  9.     }
  10. }

Displaying sObject fields using custom controller

  1. <apex:page showHeader="false" controller="AccountDataDisplayCls">
  2.   <apex:form >
  3.        <apex:pageBlock >
  4.           <apex:pageblocktable value="{!lstA}" var="A">
  5.               <apex:column headerValue="Account Name" value="{!A.Name}"/>
  6.               <apex:column headerValue="Account Phone" value="{!A.Phone}"/>
  7.           </apex:pageblocktable>
  8.       </apex:pageBlock>
  9.   </apex:form>
  10. </apex:page>
  1. public without sharing class AccountDataDisplayCls {
  2.     public List<Account> lstA{get;set;}
  3.     public AccountDataDisplayCls(){
  4.         lstA = new List<Account>();
  5.         lstA = [select id,name,phone from Account];
  6.     }
  7. }








apex:detail and rerender dynamically

  1. <apex:page standardController="Account">
  2.     <apex:pageBlock title="Contacts">
  3.         <apex:form >
  4.             <apex:dataList value="{!account.Contacts}" var="c">
  5.                 <apex:commandLink rerender="contactDetails">
  6.                     {!c.lastName}
  7.                 <apex:param name="cid" value="{!c.id}"/>
  8.                 </apex:commandLink>
  9.             </apex:dataList>
  10.         </apex:form>
  11.     </apex:pageBlock>
  12.     <apex:pageBlock title="Contact Details">
  13.         <apex:outputPanel id="contactDetails">
  14.         <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="true" title="true"/>
  15.         </apex:outputPanel>
  16.     </apex:pageBlock>
  17. </apex:page>









Comments

Popular Posts