4

I am having a little problem with visualforce and displaying a related list.

The task is to display account related contacts and opportunities as a related list on a custom object. Account is a look-up field on the custom object.

I managed to to that via <apex:relatedlist>, but with this solution links like delete or edit and buttons like newContact, merge and newOpp will open within the iFrame and not in the parent frame.

I know that there is another solution to built a custom related list with <apex:pageblock> but if I set the standardcontroller=mycustomobject__c I get an error message that the relationship is too complicated (or something like that ;-). I don't remember the exact one)

If I set the standardcontroller=Accounts I manage to display the related contacts but I can't attach it to my mycustomobject layout.

Can anyone help me here?

  1. Does anybody know how I can deal with the link and button issue?
  2. Or can anybody tell me how I can go with the second solution and attach the VF page to mycustomobject?

Thanks guys!

7
  • 1
    Try googling "Visualforce Workbook". Try some stuff out, and if you have specific code examples, come post another question. Jul 28 '14 at 16:54
  • Thanks for the "help". I already gone through this ... it seems not to deal with this kind of issue.
    – alexri
    Jul 28 '14 at 17:50
  • just to clarify, you want to create a custom visualforce page which you can then embed within your custom object's standard detail page. this visualforce page will show the related contacts and opportunities for the custom object's account look up. the actual issue you are looking to solve is that the action links within the visualforce related lists are redirecting within the same iframe instead of the entire page? Jul 28 '14 at 22:31
  • 1
    I think you can fix the navigation problem by using a facet tag in the related list to override the header, and the other issue with the subject attribute of the related list. But I would like to see the markup of your page that you've already attempted. It would help me to understand what exactly you've tried already.
    – pchittum
    Jul 29 '14 at 1:48
  • 1
    You should be able to edit your original question to include the new code there. It's confusing to have it appear in separate new answers.
    – Jagular
    Aug 8 '14 at 17:19
0

If you want to open all links in the whole window and not in the iFrame, and you can use jQuery, then this works.

<script>
  jQ = jQuery.noConflict();
  jQ('a').attr('target','_top');
</script>

It just adds to every link a target of "_top" which means "open in the whole window".

I like to drop this bit of script into the VF after any components that will have links in them and inside something that will re-render, because then if they re-render the script runs again and processes the new links. But you can run it onload too.

By the way, you probably dont need to cut the ID down from 18 chars to 15. Within salesforce either one is fine.

2
  • Hi and thanks for your answer! I can't get this to work. Maybe jQery is getting blocked somehow...
    – alexri
    Aug 18 '14 at 8:36
  • What code are you using to include jQuery?
    – Dominic
    Aug 18 '14 at 20:48
0

I have run into something similar. I'm assuming that you're using a visualforce page within a standard page layout? If so, here is a little JS/jQuery library I've put together to get around some of the difficulties I ran into. Specifically, this will address a couple of issues:

  1. Regular links will pop to the "top" (which the other answer suggested)
  2. It will display the "New" buttons within the iFrame and re-direct it back to the iframe.
  3. The "Go to list" will also be popped to the top

This will require you to call jQuery within your page, and I would recommend creating a static resource with the JS lib and jQuery. var isIframe = self !== top; //Function will re-direct if isdtp is persent

window.onload=function(){
    if(isIframe){
        var loc = ''+document.location;
        var isdtpInt=loc.indexOf('isdtp=');
        if(loc.indexOf('nonce') !== -1 && isdtpInt!==-1){
            window.location.replace(loc.substring(0,isdtpInt));
        }
    }
}
var js$ = jQuery.noConflict();

js$(document).ready(function () {
    //Looking for buttons to modify
    js$('input.btn').mouseover(function () {
        //Making sure that we're in an iframe
        if (isIframe) {
            var url = js$(this).attr("onclick");
            //Making sure that the URL exists
            if (url !== undefined) {
                //Checking if the saveURL has been defined
                if (url.indexOf("saveURL") === -1) {
                    //Getting the index of the retURL so we can push it into a saveURL
                    var retUrlStart = url.indexOf("retURL=%2F");
                    var retUrlAmp = url.indexOf("&", retUrlStart);
                    if (retUrlAmp === -1) {
                        retUrlAmp = url.indexOf("'", retUrlStart);
                    }
                    //Checking to see if the returnUl end has a location
                    if (retUrlStart !== -1 && retUrlAmp !== -1) {
                        var retUrlString = url.substring(retUrlStart, retUrlAmp);
                        var saveUrlString = retUrlString.replace("retURL", "saveURL");
                        js$(this).attr("onclick", url.replace('?', '?' + saveUrlString + '&'));
                        url =  js$(this).attr("onclick");
                    }
                }
                //Checking ot see if isdtp has been defined
                if (url.indexOf("isdtp=") === -1) {
                    js$(this).attr("onclick", url.replace('?', '?' + 'isdtp=vw' + '&'));
                    url =  js$(this).attr("onclick");
                }
            }
        }
    });
});

//Function will fix URL's of the related lists to target top if normal links, edit & del will get isdtp
js$(document).ready(function (){
    if(isIframe){
        //Checking for show more div mouseover
        js$('div.pShowMore').children().mouseover(function () {
            //Making sure that we're in an iframe
            if (self !== top) {
                //grabbing the text of the link
                var aText = js$(this).text();
                //Making sure the anchor isn't null
                if (aText !== undefined) {
                    //Checking if the anchor text has "Go to list" defined
                    if (aText.indexOf("Go to list") !== -1) {
                        //Checking if the target text has been set up to top
                        js$(this).attr('target', '_top');
                    }
                }
            }
        });
        //Hanlder for the related lists links
        js$('tr.dataRow').children().children().mouseover(function(){
            var hrefAttr = js$(this).attr('href');
            var targetAttr = js$(this).attr('target');
            if(targetAttr===undefined || targetAttr!=='_top'){
                var ancText = ''+js$(this).text();
                if(ancText!=='Edit' && ancText!=='Del'){
                    js$(this).attr('target', '_top');
                }
                else{
                    if(hrefAttr.indexOf("isdtp=") === -1){
                        js$(this).attr('href',hrefAttr.replace('?', '?' + 'isdtp=vw' + '&'));
                    }
                }
            }
        });
    }
});

There are a couple of problems that I haven't been able to get around:

  1. The save and new button doesn't function, it will simply re-direct the user back to the iframe.
  2. There is a iframe refresh when coming back from a new record being created. This is to get around Salesforce adding the 'isdtp=vw' parameter back when the page reloads (causes other issues)

It's not a perfect solution, but so far my users have been happy with the work around.

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.