I created a custom object, with a button to my visual page.

When I click on my button, I get the good redirection. The problem is that I am trying to insert in my custom object (child of account) some info.

akta__c aktaplus = new akta__c(name='test', Type_of_alert__c='yeyey');
insert aktaplus;

Because my akta__c is a child of account, I have to set up the required field account (which is normal) But because I click on the button from a specific account that already exist, I would like that field to be automatically fixed to the account from which I click on the button so the information is stored in my account page, inside my custom object

How can I do that ?

  • how you are opening visualforce page from account record page layout? Jul 26 '19 at 11:31
  • from a button created. the button is a list button that redirect to the visual page. The button appear in my custom object. So I don't know how to populate the account field so it's linked to the account from where I clicked @patelkiran3090
    – Tiburce
    Jul 26 '19 at 11:33

Consider, if applicable, using a Quick Action, optionally with Predefined Field Values (although they aren't required simply to populate the master-detail field) to create this child record.

Using a Quick Action will allow you to maintain compatibility if you should move to Lightning.

If you have other reasons to utilize a Visualforce page, change the button's content source to URL, and add the referring Account Id as a URL parameter to the page. Then, in the page's controller, use ApexPages.currentPage().getParameters() to obtain the value.

  • Hello there , thank you for the answer, I tried with the URL, it's working in classic, but when I go to lightning the URL look like : source=aloha#eyJjb21wb25lbnREZWYiOiJvbmU6YWxvaGFQYWdlIiwiYXR0cmlidXRlcyI6eyJhZGR so I cannot pass the account id as parameter.
    – Tiburce
    Jul 29 '19 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.