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
Jesus GJesus G 

Populate Id to VF from a custom button

Hello,

With the help of this post (http://bobbuzzard.blogspot.co.uk/2011/07/managing-list-of-new-records-in.html), I have created a Controller and a VF page to insert in bulk several Contacts. I have created a custom button on the Account object where the VF page is called but I would like to know how to populate the Account Id (from which the button is clicked) to the 'Account' lookup field of the contact in the VF page.

Thank you very much!
J
Best Answer chosen by Jesus G
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Jesus G,

You can pass the account ID from the custom button - 
/apex/testingnew?AccountId={!Account.Id}

And in the controller, grab the AccountId, somethinng like - 
String accountId = ApexPages.currentPage().getParameters().get('AccountId');

You have account ID in your controller, now you can populte the values of  Account' lookup field of the contact in the VF page.

Hope, it will help you.


Thanks,
Sumit Kumar Singh

 

All Answers

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Jesus G,

You can pass the account ID from the custom button - 
/apex/testingnew?AccountId={!Account.Id}

And in the controller, grab the AccountId, somethinng like - 
String accountId = ApexPages.currentPage().getParameters().get('AccountId');

You have account ID in your controller, now you can populte the values of  Account' lookup field of the contact in the VF page.

Hope, it will help you.


Thanks,
Sumit Kumar Singh

 
This was selected as the best answer
Jesus GJesus G
Hello Sumit,

Great! Many thanks for your reply. It is exactly what I needed :)

Best regards,
Jesus