+ Start a Discussion
Rahul456Rahul456 

Visualforce Page embedded in a detail page that needs to redirect to other page

Hi,

 

I have a Visualforce page embedded on the detail page of a custom object.

 

I have defined a command button in the visualforce page and has its own functionality.

 

As an Administrator, when i click on this Command button it should perform its defined functionlaity and also this detail page should be redirectd to some other page specified in the url.

 

But I click on this, only vf component is being redirected to specified but not entire detail page.

 

I had used javascript code with an onclick event on command button to perform the same but its not functioning consistently.

 

 I am now trying with apex code:

 

 Here is my sample code:

 

public pagereference reactivate(){
        ApproveItems.approveUserRequest(u.Id);
       
        String str='window.parent.location.href("/{!usr.User__r.Id}/e?retURL=%2F{!usr.User__r.Id}&active=1&Profile={!ProfileId}&Title={!URLENCODE(User_Request__c.Title__c)}&00N20000000sJNj={!User_Request__c.Legacy_User_ID__c}")';
        System.debug('######### User Id:'+ usr.User__r.Id);
       
        //PageReference newPage=new PageReference('/' + usr.User__r.Id);
        PageReference newPage=new PageReference(str);
        newPage.setRedirect(true);
        return newPage;
    }

 Regards,

Raj

 

bob_buzzardbob_buzzard

I think that the reason only the VF section gets redirected is because it is embedded in the page.  When your controller redirects, that only applies to the VF section.

 

JavaScript would be the way to go, but I'm not sure how much success you will have, as you may hit cross site scripting problems when attempting to redirect a page from a different site (i.e. from the force standard site rather than the VF  site).  What JavaScript problems are you seeing?

IvarIvar

Does anyone have a solution for this? I am at the exact same junction

lopezclopezc

Same problem, any solutions?

Daniel BallingerDaniel Ballinger

For anyone who finds this when searching for a solution, it is possible.

 

See http://stackoverflow.com/questions/11552514/visualforce-page-embedded-in-a-detail-page-that-needs-to-redirect-to-other-page

 

You can use Javascript to set window.top.location.href after the commandButton is pressed.

bob_buzzardbob_buzzard

I wrote up a blog post about this some time ago at:

 

http://bobbuzzard.blogspot.co.uk/2011/05/refreshing-record-detail-from-embedded.html

 

Please note though that this mechanism won't work inside the service console, I think because the visualforce page is embedded inside a number of windows/frames.