5

Calling an actionfunction reloads the page despite:

  1. return false from the place where we call

  2. setting rerender="emptydiv"

It says insufficient privileges in Sites (authenticated using partner portal).. but if we refresh the page again or reload by pressing enter in the url again, its not throwing that insufficient privileges error..

any ideas or suggestions to solve this problem would be much appreciated...

updated :- I have given access to all the objects and classes. when I try to preview as admin, I got this error. "Access to entity 'StaticResource' denied"

Am accessing this in my code. Not sure how to give access to this StaticResource Object for my Partner Portal User Profile.I dont find this object in the profile. Can you please help?

List<StaticResource> resourceList = [SELECT Name, NamespacePrefix, SystemModStamp 
        FROM StaticResource WHERE Name = 'MyStyles'];

This is my scenario :- I have a JQGrid. inside that I have a column in which I have a link (a tag).
Am populating data for the JQGrid from from the controller.
The method is hit as I have specified the URL parameter of JQGrid.

So whenever the pageload or any operation in the grid happens and tries to reload the grid, it hits the url and based on the JSON returned, the grid is populated.

Inside the grid, I have to show some images. for doing that am getting the images through the above code and assigning it to a property for displaying in the grid. The GetresourceURL function in the below code pulls the data from the list fetched in above code and checks what type of image is needed and does some manipulations and gives the actual resource url for the image.

I have just pasted the smaller version of the GetResourceURL code for your easy understanding.

Actually the thing here is, when i click on the application link it should log an entry in a tracking object (just to note that the user has clicked the link and its used for reporting purposes later). for this reason am doing an onclick javascript and from this am calling an actionfunction which does the job of logging in to necessary object and opens the target link in a new tab.

actually it logs the data and it tries to reload the page. not sure why it does that.. the same page is not reloaded.

if i run the visualforce page as a system administrator, but when viewing from sites url as an external customer this "Insufficient privileges" error is thrown.

So, first time the page is getting loaded. When i click on this link the page is performing actionfunction when viewed from sites, and reloading the page (which shouldnt actually reload). If it is an insufficient access for static resource how is it able to access for the first time load?

asset.ApplicationNumber = (currentAsset.Country__c == 'US' 
        && currentAsset.URL__c != null
        && !currentAsset.URL__c.contains('patentnumber'))
    ? string.format(
        '<a style="color:#0073A3;text-decoration: none; !important; cursor:pointer;" onclick="FetchDataForPatent({2},{3},{4},{5});">{1}</a>',
        new String[] {
            currentAsset.URL__c,
            currentAsset.ApplicationNumber__c,
            '\'' + currentAsset.ApplicationNumber__c + '\'',
            '\'' + currentAsset.URL__c + '\'',
            '\'' + currentAsset.Id + '\'',
            '\'' + CompanyID + '\''
        })
    : currentAsset.ApplicationNumber__c;

currentDoc.DocumentTitle__c= string.format(
    '<a style="color:#0073A3; cursor:pointer"  onclick="return FetchDataForDoc({0},{1},{2},{4},{5},{6},{7})">{3}</a>',
    new String[] {
        '\'' + currentDoc.Id + '\'',
        '\'View\'',
        '\'' + UserType + '\'',
        (GetResourceURL(resourceList, currentDoc.FileType)!='')
            ? ('<img src='+GetResourceURL(resourceList, currentDoc.FileType)
               + '> '+ currentDoc.DocumentTitle__c)
            : currentDoc.DocumentTitle__c,
        '\'' + docInfo.DocTitleWithoutImage + '\'',
        '\'' + CompanyID + '\'',
        '\'' + currentDoc.FileName__c + '\'',
        '\'' + BaseURL + '\''
    });

GetResourceURL()
{
    return ((Site.getPrefix() != null) ? Site.getCurrentSiteUrl() : '') 
        + '/resource/'
        + resourceLst[0].SystemModStamp.getTime() 
        + '/' 
        + (namespace != null && namespace != '' ? namespace + '__' : '') 
        + 'MyStyles' + '/CSS/Images/' + imageName;
}

When I use chrome developer tools to see whats happening. I am seeing an internal server error 500 :-
This error is thrown :-

this._request.send(this._query.getQueryString());
if(this._timeout>0){
    this._timeoutID=window.setTimeout(function(){
        LOG.warn("request stopped due to timeout");
        if(!_this._aborted){
            if(typeof(A4J.AJAX.onAbort)=="function"){
                A4J.AJAX.onAbort(_this);
            }
        }
    }
}

Images below:

image 1

image 2

  • 1
    Following on from Josh's answer, it's likely that the actionfunction is hitting an error, which throws you to the default insufficient privileges page. Look in the Developer Console log (uncheck 'this session only'), and try using the 'preview as admin' link from the Site detail page. – metadaddy Aug 16 '12 at 20:42
  • Excellent answers, Josh,Adam and Metadaddy.. I have given access to all the objects and classes. But Metadaddy, as you said, when I try to preview as admin, I got this error. Access to entity 'StaticResource' denied. Not sure how to give access to a profile for this staticresource object. I have updated my question so that you can help me out correctly... – Sathya Aug 21 '12 at 15:18
  • Is your controller defined 'with sharing'? If so, that might be causing the problem. Try changing it to 'without sharing' and see if you can access StaticResource. If that still doesn't work, you could create a 'shadow' custom object for StaticResource, with a trigger to add records when you add resources, and ensure the portal user profile has read access. – metadaddy Aug 21 '12 at 17:32
  • Thanks metadaddy for the quick response. I havent mentioned any sharing command at all in my class... Even then i tried adding without sharing and it didnt work.. also how come it is loading for the first time and its not able to load it when the page is reloaded? :( But Staticresource is a kind of document oriented stuff that accepts zip file right? how can we create a clone of that kind and what field types i need to create? I got the query from Force explorer. but still i have no idea of how to create this file kind of fields and access them.. can you please give a little more detail? – Sathya Aug 21 '12 at 20:01
  • Let's back up a little bit. What are you actually trying to do? It looks like you have an Apex method to turn a resource name into a URL. You can do that in the Visualforce page itself, with the URLFOR() function - see the docs here. – metadaddy Aug 22 '12 at 1:05
5

Following existing advice here, making sure that an error is not to blame, see that the Apex controller class has been included in your site's approved components:

Public Access Settings | Apex Classes | Edit

Regardless of whether your actionFunction is calling a method that does nothing but return a value, that's when your controller is invoked. To prove this, simply remove the action portion of your actionFunction, like this:

<apex:actionFunction name="test" reRender="emptydiv">

Additionally, remember that you can't re-render a non-Visualforce component, such as a div. If you're trying to re-render a div, wrap the section in an outputPanel instead:

<apex:outputPanel id="emptyoutpan">
   ...
</apex:outputPanel>

Finally, a good practice to avoid hitting your head against the wall with sites is to create a custom tab and verify your work from there as well. Then when you hit errors you will see what errors are actually being thrown, rather than simply seeing an authentication page.

  • Excellent answers, Josh and Metadaddy.. – Sathya Aug 21 '12 at 14:25
1

Regarding the StaticResource update, if I recall correctly, the StaticResource's cache control must be set to public when using w/ public facing sites. I've never seen Apex used to access the StaticResource, only VF though, so I'm not sure how the permissions relate in SOQL.

Also, VF is case sensitive w/ the rerender attribute, so make sure your rerender attribute is the same case / spelling as the id of the element you'd like to rerender. If that's not the case, then your page will reload entirely.

  • the case is right, DancinLlama and I have also set the staticresource cache control to public. :( actually i dont even need a rerender, am rerendering a junk panel.. if i dont give a rerender the whole page is getting reloaded... but unfortunately even with a rerender the page is getting reloaded :( – Sathya Aug 21 '12 at 16:01
0

The insufficient privs in Sites could refer to any point in the controller logic trying to do something that the Partner Portal would not be able to access. It also might come as the result of a Visualforce error in general.

What is the behavior of the page when not being accessed by a Portal user or Sites Guest User?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.