function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
earlino727earlino727 

Using an Embedded Visual Force Page to Redirect to a Free Standing Visual Page

HI,

 

  Is it possible that I can create a embedded Visual Force Page which can redirect to another Visual Force Page that will not be embedded into the Standard Controller parent page? I want the embedded page to function like the Command Buttons for a Standard Object's detailed page which, when created using a URL to another page can redirect you from that  Standard Object page to a Visual Force Page which exists outside of the the contact  detailed record page.  In other words a free standing Visual Force Page.

 

For example:

Say you have some contacts who are associated with an account and you would like to create a button on the Contact record  detail page that will call another page to create an opportunity for that Contact record. YOu can do this by creating a Command button and then  creating a URL link with account and contact IDs as parameters.

 

Q) Can we also do this with an Embedded Visual Force Page which contains a command button to redirect to a page outside of the Contact Detail record page?

 

 I am using a pick list of values  for this embedded page that resides within a page block section.  Underneath that pick list is a button which will redirect to another page when clicked but that new page now becomes embedded and overwrites the previous embedded page block section. I want that new page to be a free standing Visual Force Page.

 

 Thanks for your help.

Best Answer chosen by Admin (Salesforce Developers) 
robdobbyrobdobby

I didn't entire understand your last paragraph, but I think this may be what you are looking for:

 

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

 

It describes an approach to redirect from a button on an VF page that is embedded on an object detail page to another VF page.

All Answers

robdobbyrobdobby

I didn't entire understand your last paragraph, but I think this may be what you are looking for:

 

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

 

It describes an approach to redirect from a button on an VF page that is embedded on an object detail page to another VF page.

This was selected as the best answer
GlynAGlynA

Try something like this:

 

<apex:commandButton value="Go!" action="{!getURL}" rerender="url"/>
<spex:outputPanel id="url"><apex:outputPanel rendered="{!goFlag}">
<script>
    window.open( {!theURL}, '_blank' );
</script>
</apex:outputPanel></apex:outputPanel>

Your controller will have to implement the action method "public PageReference getURL()", which needs to assign the URL string to the property "public String theURL { get; set; }" and set the property "public Boolean goFlag { get; set; }" to true.  Then, when the outer outputPanel rerenders, it will render the inner outputPanel, which contains the Javascript to open a new window.  (You need two nested outputPanels, because you can't rerender something that isn't already rendered.)

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

 

EDIT:  I wrote this before looking at the StackOverflow post above.  It's basically the same code!

earlino727earlino727

Hi Glyn:  thanks  I tried the solution on Stack Over FLow and it seemed to work so I will see if I can do that with my code and let you know Just as an FYI :

 

Here is my Visual Force Page:

<apex:page sidebar="false" standardController="Contact"  extensions="AffiliateFinderExtension" tabStyle="Contact">
 <apex:form >
    <apex:pageBlock >
    
        <apex:pageBlockSection title="Order Entry Information">
           
                    <apex:outputLabel value="SelectedAccount" />
                    <apex:SelectList size="1" value="{!SelectedAccount}"  id="SelectedAccount" required="true">
                        <apex:selectOptions value="{!items}"></apex:selectOptions>
                    </apex:SelectList>
        </apex:pageBlockSection>
        <apex:pageBlockButtons location="bottom">
             <apex:commandButton value="Create Orders" action="{!CallOrderEntry}" rerender="redirectPanel" />
        </apex:pageBlockButtons>
        <apex:outputPanel id="redirectPanel" >
            <apex:outputPanel rendered="{!shouldRedirect}">
                <script type="text/javascript">
                    window.open({!redirectUrl},'_blank' );
                </script>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:pageBlock>
</apex:form>
</apex:page>

 2) Here is the Extension Controller Code:

public class AffiliateFinderExtension {
	private ApexPages.StandardController stdController;
	public String SelectedAccount{get; set;} 
	public String QueryStringContactId = null;
	public Map<String,String> MapAffiliates = new Map<String,String>();
	public List<selectOption> AccountList = new List<selectOption>();
	public List<SelectOption> getAccounts() { return AccountList; } 
	public Contact   ReferencedContact     {get;set;}
	public String Affiliations{get;set;}
	public Boolean shouldRedirect {public get; private set;}
	public String redirectUrl {public get; private set;}
	
	ApexPages.Action callOrderEntry= new ApexPages.Action('{!callOrderEntry}');
 	
	public AffiliateFinderExtension(ApexPages.StandardController stdController)
	{
	    // make the referenced contact available to the rest of the extension
            this.ReferencedContact = (Contact)stdController.getRecord();
            this.stdController = stdController;
	    system.debug('CONTACTID: '+ReferencedContact);
	    shouldRedirect = false;

	}
	 
	public List<SelectOption> getItems() {
		system.debug('CONTACTID: '+ReferencedContact);
		List<SelectOption> options = new List<SelectOption>();
		List<npe5__Affiliation__c> affiliates = [Select npe5__Organization__c,npe5__Organization__r.Name from  npe5__Affiliation__c WHERE npe5__Contact__c =:ReferencedContact.Id];
		Contact cont = [Select AccountId from Contact where Id =: ReferencedContact.Id];
		Account acct = [Select Id, Name from Account where Id =: cont.AccountId];
		 system.debug('ACCOUNZTID: '+cont.AccountId);
		options.add(new SelectOption('-- Select An Affiliate --','-- Select An Affiliate --'));
		options.add(new SelectOption(acct.Id, acct.Name));
		MapAffiliates.put(acct.Id, acct.Name);
		system.debug('AFfiliates: '+affiliates );
		for(npe5__Affiliation__c aff: affiliates ){
			options.add(new SelectOption(aff.npe5__Organization__c, aff.npe5__Organization__r.Name));
			MapAffiliates.put(aff.npe5__Organization__r.Name,aff.npe5__Organization__c);
		}
		
		return options;
	}
	
	
      public PageReference CallOrderEntry()
      {
    	String SearchURL = Page.orderentry4.getUrl();
    	system.debug('URL: '+SearchURL);
    	
        PageReference RedirectPage = new PageReference(SearchURL);
        RedirectPage.getParameters().clear();
        system.debug('URL: '+SearchURL);
        
        if(SelectedAccount != '-- Select An Affiliate --' && SelectedAccount != '') {	
        		
    			RedirectPage.getParameters().put('aid',''+SelectedAccount+''); 
    			RedirectPage.getParameters().put('cid', ''+ReferencedContact.Id+'');
    				
    	} 
    	system.debug('PAGE-AID: '+SelectedAccount);
    	system.debug('PAGE-CID: '+ReferencedContact.Id);
    	RedirectPage.setRedirect(true);
       	shouldRedirect = true;
        redirectUrl = SearchURL;
        return RedirectPage;
     }
	
}// Class

 Thanks

 

earlino727earlino727

Rob Dobby:  thanks I will try this solution you gave and let you and Glyn A know what happens. So far I tried the test code in Stack Overflow but I just changes the Standard Controller getURL vallue to match the URL  of the desired page I wanted to Redirect. Thanks much.

 

earlino727earlino727

I tried it on my code and it worked. Both you and Rob deserve the credit but I don;t think I can check both. Thanks much for your help.

GlynAGlynA

No worries.  I'm glad you got it to work.  Rob deserves the credit for getting the answer first.  However, you could give us both kudos if you want.  -Glyn