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
vedikavedika 

Insert custom object related record on contact object Please help!!!

I have a requirement to create visual force page which takes contact Id from URL and create related record . Below code does'nt give any error but also not save given input values into record though the related record is created with empty fields. Any help is highly appreciated

public with sharing class ChildContactControllerApex {
    public Contact mycontact {get; set;}
    public Emergency_Contact_Information__c Econ{get; set;}
        public ChildContactControllerApex(ApexPages.StandardController controller) {
        Id id = ApexPages.currentPage().getParameters().get('id');
        system.debug(id);
        mycontact =[SELECT Id, FirstName,LastName From Contact WHERE Id = :id];
                                                     
    }
    
    public contact getcontact()
    {
        return mycontact;
        
    }
    
    public Emergency_Contact_Information__c getEcon()
    {
        return Econ;
     }
    
    
    public PageReference save()
    {
        try{
            Emergency_Contact_Information__c EmergencyContact = new Emergency_Contact_Information__c();
            EmergencyContact.Contact__c= mycontact.Id;
            Insert EmergencyContact;
            }
        catch (DMLException e) {
       System.debug('Exception occured : ' + e.getMessage());
     }
       return null;
    }}



<apex:page controller="EmergencyControllerApex" tabStyle="Contact">
    <apex:form >
            <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:outputField value="{!Contact.FirstName}"/><br></br>
                <apex:outputField value="{!Contact.LastName}"/><br></br>
                <apex:inputField value="{!Contact.Emergency_Contact_Name__c}"/><br></br>
                <apex:inputField value="{!contact.Emergency_Contact_Relationship__c}"/><br></br>
                <apex:inputField value="{!Contact.Emergency_Contact_Phone__c}"/><br></br>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>