[Salesforce] - Create record for different objects from same Page Layout 




Code for Visualforce page - 
<apex:page controller="StudTeachUpdate">
<apex:form >
<apex:pageblock >
<apex:pageblockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageblockButtons>
<apex:pageblockSection title="Student">
<apex:inputField value="{!stud.Student_Name__c}"/>
<apex:inputField value="{!stud.Email_Id__c}"/>
<apex:inputField value="{!stud.Country__c}"/>

</apex:pageblockSection>

<apex:pageblockSection title="Professor">
<apex:inputField value="{!prof.Name}"/>
<apex:inputfield value="{!prof.Email_id__c}"/>
</apex:pageblockSection>

</apex:pageblock>
  </apex:form>
</apex:page>


Code for Controller - 
public class StudTeachUpdate {

public Student__c stud{get;set;}
public Professor__c prof{get;set;}

    public StudTeachUpdate ()
    {
        stud= new Student__c ();
        prof = new Professor__c();

    }
public pagereference save()
{
insert stud;
insert prof;

return null;
}

}