You need to sign in to do that
Don't have an account?
ForceRookie
Insert multiple objects’s data in one controller
I created a visualforce page in which it has
form for create new contact,
form for create new account,
and form for create new opportunity..
inside <apex:form>
(Fields are dynamic)
Task:
- create variable in controller for Contact’s LastName and variable for Account’s Name and call it in InputText in VF.
- if I created a new contact, and new opportunity, the Contact will be the Primary Contact of the Opportunity created.
Help me to improve my Controller.
Thanks in advance, I’ll appreciate the help..
form for create new contact,
form for create new account,
and form for create new opportunity..
inside <apex:form>
(Fields are dynamic)
Task:
- create variable in controller for Contact’s LastName and variable for Account’s Name and call it in InputText in VF.
- if I created a new contact, and new opportunity, the Contact will be the Primary Contact of the Opportunity created.
Help me to improve my Controller.
Thanks in advance, I’ll appreciate the help..
public class myController { public Contact con {get;set;} public Account acc {get;set;} public Opportunity opp {get;set;} public Contact getcon() { return con; } public Account getacc() { return acc; } public Opportunity getopp() { return opp; } public PageReference save() { insert con; insert acc; insert opp; return null; } }
All Answers
CONTROLLER CODE: VF PAGE CODE:
If this answer solves your problem then mark it as the solution to help others. Thanks.
For example: Suppose Email field on Contact object is required then you need to put an extra field on your VF Page like this:
<apex:inputField value="{!con.Email}"/>
So you need to find out all the required field for all three objects and put on your VF page.
Update your controller code to this for PrimaryContact field, I am assuming that the field API name is Primary_Contact__c.
I have one favor, will you help me with its Test Class? ‘Coz I can’t find anything when I searched. Hoping for your reply again :)