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
Manish Anand 10Manish Anand 10 

Create a contact and associate with an account in visualforce and apex

Hi,

My requirement is to create a button/link on account detail page on the first visualforce page.Clicking on that button should open second visualforce page, which will have Account Name (from First visualforce page) and 'Add New Contact'. button.Clicking on 'Add New Contact' will open third visualforce page, where I can enter Contact's first name and last name and save the contact.
Newly created contact's account name will be same as that of Account name from first visualforce page.

Regards,
Manish
William TranWilliam Tran
Manish, you need to do what you stated, in theory you only need 2 VF pages and 1 standard page

1) Create a VF page for Account - should use <apex:page standardController="Account">
2) Create a VF page for Contact - should use <apex:page standardController="Contact">
3) Create the custom button on standar account detail page to launch the 1) VF page.

Feel free to post questions if you run into issues.

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks