You need to sign in to do that
Don't have an account?
vedika
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>
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>