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

Strange Behavior on Overridden View/Edit link for Portal Users logging in via a Sites page

I have a Customer Portal where I've created a Site for the users to login from. This problem only appears when logging into the Portal via the Site. If they login using the standard Portal URL there is no problem, but of course we want the users to login via the Sites page.


If I override the VIEW or EDIT links on a Custom Object, when the user clicks the EDIT link or the item NAME in a View, they get an error for "Page Not Found" (the error below is a VIEW link error):


Page Not Found: /portalpage/a1CQ0000000ouMS/e 


If I remove the override for the VIEW, when the user clicks the link it opens up the page properly, and it even shows the exact same URL that appeared in the error message.


Very bizzarre. The page exists either way, but for some reason the overridden link is creating an issue.


I confirmed that the VisualForce page used in the override is available to the Portal User and Sites user Profiles and checked any other security setting I can think of. Doesn't seem to be a security setting, especially given the odd page not found error, but who knows.


Is there a way I can override the VIEW/EDIT page for a Custom Object and have that override work for Portal Users that login via a Sites page?



Best Regards,




I was able to find a creative work-around for this. In general, I did not want to rebuild every list and page using VisualForce just to get the links to work on my portal-site. So, to work-around the PageNotFound error, I created a custom PageNotFound VisualForce page that detects the "error" and just redirects the user to the correct page:



<apex:page showHeader="false" title="{!$}" >


String.prototype.startsWith = function(s) { if( this.indexOf(s) == 0 ) return true; return false; }
String.prototype.endsWith = function(str) { return (this.match(str+"$")==str) }

    var originalURL = "{!$Site.OriginalUrl}";
    var targetID = '';
    var action = 'view';
    if (originalURL.startsWith('/portal/apex/')) targetID = originalURL.substr(13,15); 
    if (originalURL.startsWith('/apex/')) targetID = originalURL.substr(6,15); 
    if (originalURL.startsWith('/portal/')) targetID = originalURL.substr(8,15); 
    if (originalURL.endsWith('/e')) action = 'edit';

    // Redirect to the Participant EDIT page 
    if (originalURL.startsWith('/portal/a1CQ') || originalURL.startsWith('/portal/a185'))
        window.location.href = '/portal/apex/Portal_Participant_Entry?ID=' + targetID;

    // Redirect to the State VIEW page 
    if (originalURL.startsWith('/portal/a19Q') || originalURL.startsWith('/portal/a1B5'))
        window.location.href = '/portal/apex/Portal_MyState';

    // Redirect to the Workshop VIEW page 
    if (originalURL.startsWith('/portal/a1BQ') || originalURL.startsWith('/portal/a195'))
        window.location.href = '/portal/apex/Portal_Workshop?id=' + targetID;


<!-- The rest of the page is from the standard FileNotFound visualforce page -->
  <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  
        <apex:panelGrid bgcolor="white" columns="1"> 
          <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="1" styleClass="topPanelContainer"> 
            <apex:outputPanel layout="block" styleClass="topPanel">
              <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="3"> 
                <apex:image value="{!$Resource.PortalLogo}" style="align: center;" />
                <apex:panelGroup >
                  <apex:outputText styleClass="title" value="{!$}">      
                   <apex:param value="{!$Site.OriginalUrl}"/>
                  <apex:outputText value="{!$}"/>
                  <apex:outputText escape="false" value=" {!$}">
                   <apex:param value="mailto:{!$Site.AdminEmailAddress}"/>
                   <apex:param value="{!$}"/>
          <apex:messages />





Best Regards,



Rich PRich P

I was having the same problem and this worked for me. Thanks!


we will look in to this. It should work without the workaround



Rich PRich P

Thanks. In my case, I have a custom object with an overridden edit button linking to a visualforce page. As Mike said, it works for regular users, but not on the Customer Portal. I used the following modification of Mike's example to get it working:


    if (originalURL.startsWith('/invest2010/')) targetID = originalURL.substr(12,15); 
    if (originalURL.endsWith('/e')) action = 'edit';

    if (originalURL.startsWith('/invest2010/a01Q') || originalURL.startsWith('/invest2010/a018'))
        window.location.href = '/invest2010/apex/ApplicationEvaluation?id=' + targetID;


I will be happy to share further access to our code if you have any questions.





We have logged a bug for this and working on it. You shouldn't need to do any workaround it should just work if you overwrite the buttons with a visualforce pages.