Inserting records into Custom Object Using Controller in Visualforce page.

By | October 18, 2019

Vf Page

<apex:page Controller="AddEmployeeRecordsCtrl" showHeader="true" sidebar="true">
    <apex:form >
        <apex:pageblock >
            <apex:pageblocksection >
                <apex:inputField value="{!emp.Name}"/>
            </apex:pageblocksection >
            <apex:pageblockbuttons >
                <apex:commandButton action="{!SaveRecord}" value="Save" />
            </apex:pageblockbuttons>            
        </apex:pageblock>
    </apex:form>
</apex:page>

APEX CONTROLLER

public with sharing class AddEmployeeRecordsCtrl{
    public Employee__c emp {set;get;}
    public void SaveRecord(){
        Employee__c emp = New Employee__c();
        insert emp;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *