[SalesForce] VF Page not working in Partner Community Page

I have a VF page which is working fine in my Salesforce org, but when I try to open it via Partner Community login, I get an error saying "Page is under construction". On further research I found that this is due to the Custom button which actually invokes the page via Javascript as the URL has been coded as '/apex/page/params' but the partner community URL would be '/partnercommunity/page/param'. I am posting my Custom button javascript code below:

{!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")} 
var selected = {!GETRECORDIDS($ObjectType.Custom_Obj__c)}; 
if (selected[0] == null) { 
alert("Please select at least one record!")
}
else {
window.open('/apex/myVFPage?rec='+selected.join(','), '_blank');
}

This custom button will be available on a list view which when pressed will opena vf page which downloads all the currently selected records. As mentioned, the code is working fine in my org, its only the Partner community which is causing the issue.
Could anyone please suggest as to how I need to change the button code so that it works for both internal and external users.
Let me know in case any other info is needed.

Best Answer

Replace the below line

window.open('/apex/myVFPage?rec='+selected.join(','), '_blank');

With

window.parent.location.href="{!URLFOR($Site.Prefix+'/apex/myVFPage?rec=')}"+selected.join(',') 

Let me know if it work for you and please do not forget to mark as answer if it works ! :)

Cheers,

Rajeev :)

Related Topic