2

I have a created a simple VF page

<apex:page standardController="Delivery__c" sidebar="false" >
    <apex:relatedList list="Addresses__r"/>
</apex:page>

Now I have added this VF page to a section on a custom Object : Delivery__c pagelayout . And is shown as expected.

enter image description here

Now when i click on new address it opens in that section and not in a new window. Is there any way that I can override this standard button and navigate to the url i want.enter image description here . I want to do this on my VF page and not by overriding the standard buttons in salesforce Buttons, Actions and Links section.

  • Its confusing. You created a custom button ? is Create Address that button to which you have assigned that VF page ? – Muzammil Bajaria Apr 12 '17 at 17:41
  • I created a VF page and added to a section on Delivery__c page layout. In that visual force page I am just displaying the related list Addresses__r. so I am able to see the related list as expected as shown in img1 . But when I click on New Address button ( on vf page which i am displaying as a section ) it opens inside that section and not in a new window. Is there a way that i can override the New Address button in relatedlist. – KSR Apr 12 '17 at 18:08
3

You could use some simple JavaScript for this:

<apex:page standardController="Delivery__c" sidebar="false" >
    <script>
    window.addEventListener("click", function(event) {
        if(event.target.tagName === "BUTTON" && event.target.innerText === "New Address") {
            event.preventDefault();
            window.open("{!URLFOR($Action.Address__c.New, null, [])}", "_blank");
        }
    })
    </script>
    <apex:relatedList list="Addresses__r"/>
</apex:page>

You may need to add additional parameters in the [] to link the parent Id. You'll want to base it off the URL that's presented when you click the button by default. It'll have two params, like CF00N000000000000 and CF00N000000000000_lkid.

| improve this answer | |
  • Hi , Thank you for the quick reply. I have na3.salesforce.com/a01/… &retURL=%2Fapex%2Fnotesandrelatedlist%3FId%3Da0Y5000000AneHd%26core.apexpages.devmode.url%3D1 . How do I pass these two parameters in URLFOR , please guide me – KSR Apr 12 '17 at 19:43
0

You could use JavaScript to set the target on all links in that page to open in a new window.

Add this just before </page> to your VF markup:

<script>
  var links = document.getElementsByTagName('a');

  for (var i=0, len=links.length; i < len; i ++) {
    links[i].target = '_blank';
  }
</script>
| improve this answer | |
  • 2
    This won't work for AJAX-loaded elements, though. – sfdcfox Apr 12 '17 at 18:46

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.