0

I wish to replace/remove the default new button (refer to image below). Right now, this button shows a Visualforce page when clicked. I have overridden the default new button by a VF page.

IMAGE 1 (this is the detail object's default list view)

However, this override also overrides the related list button on the parent object like this :

IMAGE 2 (this is the parent object's related list)

The button that you see here is a custom button that shows the default "New Enroled Contact" screen. However, this button is not working for some reason... it is showing the same VF page as the list view button.

How do I change the behaviour of list view button while retaining related list button's behaviour?

I could use a visualforce page, but how would I identify from where the page is being called?

1 Answer 1

0

These two will result in the same Visualforce page.

For distinguishing the source, you can refer to my related question: How to pass parameter in the new button to VF page in related list section

Basically, you can use the following code:

public MyController(ApexPages.StandardController ctrl) {
    MySObject__c record = (MySObject__c)ctrl.getRecord();
    Id parentId = record.ParentField__c;
    // if(parentId != null)
}

To redirect and add the logic.

However, the above approach seems a pain and a little bit clunky to me.

I would recommend you create another list button for this object. And add that list button into your related list section and hide the new button in related list. That can easily fix your issue.

8
  • Thank you for the fast response, Lance, but the button in the list view is ALREADY a custom button. Its code is thus : /a07/e?00NN0000001xDrI={!Enrolment__c.Name} . The first 3 letters refer to detail object, the next bunch is for auto populating the field on the detail object.
    – fraglord
    Commented Sep 27, 2016 at 5:36
  • @fraglord I understand it is already a Visualforce page. I mean create ANOTHER custom button and ANOTHER visualforce page and hide the current one on your parent object's page layout, related list section. You can also use the parentId field to distinguish if you want
    – Lance Shi
    Commented Sep 27, 2016 at 5:45
  • OK, as far as I understand : 1. user clicks "New" button. 2. VF page is called. 3. VF page controller checks if there's a parentID present. If yes, then it throws an error, else it sends the user to the URL I linked in the previous comment. Correct?
    – fraglord
    Commented Sep 27, 2016 at 5:49
  • @fraglord No. The url in your previous comment is basically an edit page url. If you have overridden the new button, you have overridden the url as well. What I understand from your question is, if the parentId is not null, it means coming from the list, should redirect to your VF page. If parentId is null, redirect to something like standard new page, which should be another VF page mimicing the standard new page behaviour
    – Lance Shi
    Commented Sep 27, 2016 at 5:55
  • @fraglord Or otherwise, as I have suggested. Create another custom button say call it custom new. And use a VF page for it to mimic the standard new page scenario. Add that button to your related list and remove your current new button from the related list.
    – Lance Shi
    Commented Sep 27, 2016 at 5:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .