Monday, January 21, 2013

Default Text :

Default Text :
This example shows how to generate a default text in your required fields. You can try sample example using  your custom object api.  Here once you created visualforce page override your new button on your custom object with this vfp.

public class AcctPlatformExtension {
  public AcctPlatformExtension(ApexPages.StandardController controller) {
    Forecast__c t = (Forecast__c)controller.getRecord();
    t.Name= 'AutoGeneratedName';
  }
  public static testMethod void test() {
   Forecast__c t = new Forecast__c();
    ApexPages.StandardController controller = new ApexPages.StandardController(t);
    AcctPlatformExtension extension = new AcctPlatformExtension(controller);
    System.assertEquals(t.Name,'AutoGeneratedName');
  }
}

<apex:page standardController="Forecast__c" extensions="AcctPlatformExtension">
<apex:sectionHeader title="Forecast__c Edit" subtitle="{!Forecast__c.name}"/>
 <apex:form > <apex:pageBlock title="Forecast__c Edit" mode="edit">
 <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!save}"/>
 <apex:commandButton value="Save & New" action="{!save}" />
  <apex:commandButton value="Cancel" action="{!cancel}"/>
   </apex:pageBlockButtons> <apex:pageBlockButtons location="bottom">
   <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Save & New" action="{!save}" />
    <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2">
     <apex:inputField value="{!Forecast__c.Name}" required="true" />
     <apex:inputField value="{!Forecast__c.OwnerId}" required="false"/>
     <apex:inputField value="{!Forecast__c.Status__c}" required="false"/>
     <apex:inputField value="{!Forecast__c.Civil_Military__c}" required="false"/>
      <apex:inputField value="{!Forecast__c.Airframer__c}" required="true"/>
      <apex:inputField value="{!Forecast__c.Account_Sub_Type__c}" required="false"/>
      <apex:inputField value="{!Forecast__c.Forecast_Platform__c}" required="true"/>
      <apex:inputField value="{!Forecast__c.Sales_Org__c}" required="false"/>
      <apex:inputField value="{!Forecast__c.Child_Account__c}" required="false"/>
       <apex:inputField value="{!Forecast__c.Region__c}" required="false"/>
       </apex:pageBlockSection> </apex:pageBlock>
       </apex:form>
       </apex:page>



No comments:

Post a Comment