+ Start a Discussion
SathishKumarSathishKumar 

Create Records(Account, Opportunity and Contact) from VF page

Hi guys,

I want to devlop a vf page where i can create records in Account, opportunity and Contact. Opportunity and contact records must be associated with the Account.

Thanks in advance.
Rakesh ARakesh A
Create a VF page to show Account, Opportunity and Contact forms in 3 Sections.
Create a custom sontroller and there create properties (get; set;) for all fields.
Create Accout and after create and Contact and Opportunity using Account Id, as below sample code.

Account acc = new Account();
acc.Name = AccountName;  //AccountName is property/Variable
//add remaining fields
insert acc;

Contact con = new Contact();
con.LastName = ContactName;  //ContactName is property/Variable
con.AccountId = acc.Id;
//add remaining fields
insert con;

Opportunity opp = new Opportunity ();
opp.Name = OppName;    ///OppName is property/Variable
opp.AccountId = acc.Id;
//add remaining fields
insert opp;