function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
noor Zabinoor Zabi 

Create a Common VF page to insert data to the Student and Teacher Object---Mark all fields as mandatory at page level (not in object).

VIsual Force Page:-
<apex:page controller="StudentController">
  <apex:form id="test" >
<apex:pageMessages/>
      <apex:pageBlock title="Choose the Object To Create Records:" >   
       <center>
          <apex:selectList value="{!source}" size="1" required="true" >
              <apex:selectOptions value="{!sourceValue}" />
              <apex:actionSupport event="onchange" action="{!objectDisplay}" reRender="test"/>
          </apex:selectList> 
       </center>   
      </apex:pageBlock>
      <apex:pageBlock rendered="{!flag}">   
          <apex:pageBlockSection title="Create Student Details" columns="1" >
           
            <apex:inputField value="{!stu1.Salutation__c}" required="true"/>
            <apex:inputField value="{!stu1.Name}" required="true"/>
            <apex:inputField value="{!stu1.Last_Name__c}" required="true"/>
            <apex:inputField value="{!stu1.Gender__c}"  required="true"/>
            <apex:inputField value="{!stu1.DOB__c}"  required="true"/>
            <apex:inputField value="{!stu1.Class__c}"  required="true"/>
            <apex:inputField value="{!stu1.Division__c}" required="true"/>
              
          </apex:pageBlockSection>         
     </apex:pageBlock>
       <apex:pageBlock rendered="{!flag1}">        
          <apex:pageBlockSection title="Create Teacher Details" columns="2" >
          
            <apex:inputField value="{!tch1.Salutation__c}" required="true" />
            <apex:inputField value="{!tch1.Name}" required="true"/>
            <apex:inputField value="{!tch1.Last_Name__c}"  required="true"/>
            <apex:inputField value="{!tch1.Gender__c}" required="true"/>
            <apex:inputField value="{!tch1.DOB__c}" required="true"/>
            <apex:inputField value="{!tch1.Class__c}"  required="true"/>
            <apex:inputField value="{!tch1.Division__c}" required="true" />

          </apex:pageBlockSection>
         
      </apex:pageBlock>
      <apex:pageBlock rendered="{!flag2}">
        <apex:pageBlockSection>
            <apex:commandButton value="Save" action="{!SaveRecord}" />
            <apex:commandButton value="Clear" action="{!clearFunction}" />
        </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

Class:--

public with sharing class StudentController {
    public string source {get;set;}
    public List<selectOption> sourceValue {get;set;}
    public boolean flag {get;set;}
    public boolean flag1 {get;set;}
    public boolean flag2 {get;set;}
    public Students__c stu1{get;set;}
    public Teacher__c tch1{get;set;}
    
    
    public StudentController()
    {
        flag = false;
        flag1 = false;
        flag2 = false;
        stu1 = new Students__c();
        tch1 = new Teacher__c();
        sourceValue = new List<selectOption>();
        sourceValue.add(new selectOption('','--select--'));
        sourceValue.add(new selectOption('Students','Students'));
        sourceValue.add(new selectOption('Teacher','Teacher'));
    }
    
    public void objectDisplay()
    { 
         If(source == 'Students'){
            flag = true;
            flag2= true;
            flag1 = false;
        }
        else if(source == 'Teacher'){
            flag1 = true;
            flag2= true;
            flag = false;
        }
    }
    public void saveRecord() {
        if(source=='Students') {
        insert stu1;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,' Record Created Successfully.Thank you!'));
        stu1 = new Students__c();
        }
        else {
            insert tch1;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,' Record Created Successfully.Thank you!'));
            tch1 = new Teacher__c();
        }
    }
    public void clearFunction(){
        if(source=='Students') {
        stu1 = new Students__c();
        }
        else{
        tch1 = new Teacher__c();
        }
    }
}

When i  use required = true  in input fields it is working, but i change theUser-added image select option from student to teacher or teacher to student. I'm getting this error
 
Todkar AishwaryaTodkar Aishwarya
Hi,

Use actionRegion for this. 
<apex:actionRegion >
       <apex:selectList value="{!source}" size="1" required="true" >
              <apex:selectOptions value="{!sourceValue}" />
              <apex:actionSupport event="onchange" action="{!objectDisplay}" reRender="test"/>
     </apex:selectList> 
</apex:actionRegion >

Thanks!
Theresa StocktonTheresa Stockton
Hello, I am a college student and recently I have got an assignment from my mentor and for that, I am searching for how to create a common VF page to insert data to the Student and Teacher Object and I am glad I have found your post in I have found my question answer. I was so worried regarding my project because I have also a lot of assignments to do but because of my project, I can't write them. But I am glad I have found Edubirdie and after reading an article on https://edubirdie.net/blog/is-edubirdie-legal-or-cheating  site, I have taken help from them. And now I can concentrate on my project easily. Thank you so much Todkar Aishwarya for sharing that code with us.
noor Zabinoor Zabi
U need to save that image in static Resource, then u need to call that image.