Play Games

Search This Blog

Thursday, March 5, 2020

Salesforce Record Creation Example in Visualforce Page - Salesforce Globe For You

Salesforce Record Creation Example in Visualforce Page  - Salesforce Globe For You 

Apex Class: RecordCreationController
public class RecordCreationController {
    public Account acc {get;set;}
    public RecordCreationController() {
        acc = new Account();
    }
    public PageReference saveRecord() {
        insert acc;
        system.debug('Account:'+acc);
        PageReference acctPage = new ApexPages.StandardController(acc).view();
        acctPage.setRedirect(true);
        return acctPage;
    }
}

Visualforce Page: Record Creation
<apex:page controller="RecordCreationController">
  <apex:sectionHeader title="New Account Creation" />
    <apex:form >
        <apex:pageBlock title="Create a New Account">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!saveRecord}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Account Information">
                <apex:inputField  value="{!acc.name}"/>
                <apex:inputField  value="{!acc.site}"/>
            </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>
Ouput:


No comments:

Post a Comment