Friday, March 15, 2013

Inserting a record using Standard Controller and Extension


Visualforce Page: 

<apex:page standardController="Student__c" extensions="insertcls" >
     <apex:form >       
            <apex:pageblock title="Student Edit">
                    <apex:pageblockSection title="Information">
                            <apex:inputField value="{!stud.name}" required="true"/>
                            <apex:inputField value="{!stud.Batch__c}"/>
                            <apex:inputField value="{!stud.StudentFee__c}"/>
                            <apex:inputField value="{!stud.Gender__c}"/>
                    </apex:pageblockSection>
                    <apex:pageblockButtons >
                        <apex:commandButton value="Save" action="{!saverec}"/>
                    </apex:pageblockButtons>
            </apex:pageblock>        
     </apex:form>
</apex:page>

Apex Class:

public with sharing class insertcls {

    public insertcls(ApexPages.StandardController controller) {
         stud = new Student__c();
                                                                                            }

    public pagereference saverec(){
        insert stud;
        System.debug('-------------'+stud.id);
        pagereference ref= new pagereference('/'+stud.id);
        return ref;
                                                    }
    public student__c stud{get; set;}
                                                      }

No comments:

Post a Comment