+ Start a Discussion
Jeff OnsrudJeff Onsrud 

Partner Community Visualforce Page URL vs Internal User URL

I am trying to override the Edit functionality on a related list on an object with a Visualforce page. My issue is that there is only 1 override to the standard Edit link for an Object for ALL users (internal or external) and it wants to launch the same Visualforce page regardless of if you are in the standard salesforce instance (internal user) or if you are in a Partner Community (external user).

This is a problem because links to internal visualforce URLs need to be "/apex/VisualforcePageName" where external pages need to just be "VisualforcePageName". For example the full URL would look like http://na2.salesforce.com/apex/VisualforcePageName for internal and for the community site it would be http://mydomain.force.com/sitename/VisualforcePageName .

Specifially my code is using a Javascript to open a new window with a relative link:
<script>
        window.onload = newPage();
        var popUp;
        function newPage()
        {
            if ({!ContinueForm} == true)
            {
                popUp = window.open('/apex/VisualforcePageName?cid={!ConfigId}');
                if (popUp == null || typeof(popUp)=='undefined') 
                {   
                    alert('Please disable your pop-up blocker or allow pop-ups from "{!URLInfo}" and click link again.'); 
                }
            }
            redirectPage();
        }
</script>

If there is another way to open a link to a visualforce page in a New Window (for both Internal and Community) I am ok going that route too instead of trying to modify the URL.

Thanks!
Best Answer chosen by Jeff Onsrud
Jason BealJason Beal
You can use the $Page global variable to construct your URL. On your visualforce page use {!$Page.VisualforcePageName} to get the path to your page. You can also use the URLFOR function to add your parameters, see the example below.
window.open('{!URLFOR($Page.VisualforcePageName,null,[cid=ConfigId])}');


 

All Answers

Jason BealJason Beal
You can use the $Page global variable to construct your URL. On your visualforce page use {!$Page.VisualforcePageName} to get the path to your page. You can also use the URLFOR function to add your parameters, see the example below.
window.open('{!URLFOR($Page.VisualforcePageName,null,[cid=ConfigId])}');


 
This was selected as the best answer
Jeff OnsrudJeff Onsrud
@[Jason Beal] Thanks for the help.. that did it!

I spent hours on the phone with support and they weren't able to help. I should have started here.
Jeff OnsrudJeff Onsrud
I have one more related question. What if I want to specify content that is being generated? For example the URL in my normal na10 instance would be:
'https://c.na10.content.force.com/servlet/servlet.FileDownload?file='+fileID.getId()

If I use the '{!URLFOR($Page.FileDownload?file=,null,[cid=fileID])}' I get an error that "Formula Expression is required on the Action Attribute".

Any help would be greatly appreciated.