You need to sign in to do that
Don't have an account?
Aditya Rayavarapu 5
Insert Parent and Child in one step
Hello,
I have a lookup relationship between Contact (Master) and Dependant__c (Child). The lookup field is called Primary__c.
I have a VF page where you can enter the contact details, and also the dependant details. When you click 'Save', both the contact and dependant save. However, I want the dependant to have a lookup relation to this specific contact. How can I achieve this? I have tried to get the record ID of the contact before inserting the dependant, but I cannot get the getting the Id part of the code right.
VF PAGE (simplified) :
<apex:page controller="customcontroller">
<apex:form>
<apex:inputfield value="{!c.LastName}" />
<apex:inputfield value="{!d.Name__c}"/>
<apex:commandButton action="{!save}" value="Save"/>
</apex:form>
</apex:page>
CONTROLLER:
public class CustomController {
public Contact c {get; set;}
public Dependant__c d {get;set;}
public void save(){
insert c;
Primary__c=('Select Name from Contact') //unclear about getting the Contact record ID for this part
insert d;
}
}
Thanks,
Adi
I have a lookup relationship between Contact (Master) and Dependant__c (Child). The lookup field is called Primary__c.
I have a VF page where you can enter the contact details, and also the dependant details. When you click 'Save', both the contact and dependant save. However, I want the dependant to have a lookup relation to this specific contact. How can I achieve this? I have tried to get the record ID of the contact before inserting the dependant, but I cannot get the getting the Id part of the code right.
VF PAGE (simplified) :
<apex:page controller="customcontroller">
<apex:form>
<apex:inputfield value="{!c.LastName}" />
<apex:inputfield value="{!d.Name__c}"/>
<apex:commandButton action="{!save}" value="Save"/>
</apex:form>
</apex:page>
CONTROLLER:
public class CustomController {
public Contact c {get; set;}
public Dependant__c d {get;set;}
public void save(){
insert c;
Primary__c=('Select Name from Contact') //unclear about getting the Contact record ID for this part
insert d;
}
}
Thanks,
Adi
http://bobbuzzard.blogspot.co.uk/2012/03/create-parent-and-child-records-in-one.html
All Answers
http://bobbuzzard.blogspot.co.uk/2012/03/create-parent-and-child-records-in-one.html
Big fan of your blog!