5

I am trying to debug a visual force page that fails with a generic "Error: Error occurred while loading a Visualforce page."

I have set the debug log to the finest settings possible, but all it gives me is this:

16.0 APEX_CODE,FINEST;APEX_PROFILING,FINEST;CALLOUT,INFO;DB,FINEST;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,FINER;WORKFLOW,INFO
08:01:04.034 (34312000)|EXECUTION_STARTED
08:01:04.034 (34540000)|CODE_UNIT_STARTED|[EXTERNAL]|066700000004clj|VF: /apex/Exception
08:01:04.068 (68281000)|VF_EVALUATE_FORMULA_BEGIN|066700000004clj|#{AND(ISPICKVAL($User.UserType,'Guest'), $Site.LoginEnabled)}
08:01:04.081 (81502000)|VF_EVALUATE_FORMULA_END  // the rest is all just the error page rendering
08:01:04.081 (81693000)|VF_EVALUATE_FORMULA_BEGIN|066700000004clj|#{NOT(ISPICKVAL($User.UserType,'Guest'))}
08:01:04.081 (81772000)|VF_EVALUATE_FORMULA_END
08:01:04.082 (82687000)|VF_EVALUATE_FORMULA_BEGIN|066700000004clj|#{$Site.Prefix}#{$Label.site.img_path}/force_logo.gif
08:01:04.082 (82862000)|VF_EVALUATE_FORMULA_END

The fact that it says so little, does this give any clue to the possible error? I've got debug comments in the page controller constructor that I am not seeing, so I'm sure it doesn't get as far as the constructor. What can happen pre-constructor?

Some more information about this specific situation that may be relevant: The page has an HTML form on it and renders perfectly when viewed. It only crashes when I post form data to the page.

Update:

This is a Customer Portal page and running the page not through the portal gave this error:

Update failed. First exception on row 0 with id a0G70000004ED4yEAG; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []

This is turning into a different question, but does anyone know which permissions to check and how?

To isolate the error I simplified it down to this page:

<apex:page controller="utilController" action="{!init}" standardstylesheets="false" showHeader="false" sidebar="false"  doctype="html-5.0">
  <head>
    <title>Utility Page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>

  <body>
    <h1>{!sourceName}</h1>
    <form method="post">
        <div>
            <label>Product:</label>
            <input name="product_code" type="text" size="12" value="{!productCode}" />
        </div>
        <input type="submit" value="Save Settings" />
</form>
</body>
</apex:page>

served with this controller:

public with sharing class utilController {

    public String productCode {get; set;}
    public String sourceName {get; set;}

    public utilController(){
        System.debug('**** Contructor ');
    }

    public void init() {
        Map<String, String> params = ApexPages.currentPage().getParameters();
        Input_Source__c source = readSource();

        /* is this a form post */
        if (params.get('product_code') != null) {
            try {
                source.Product__c = params.get('product_code');
                update source;  // throws INSUFFICIENT_ACCESS_OR_READONLY error
            } 
            catch (Exception e) {
                System.debug('**** Exception: ' + e.getMessage());  
            }
        }

        sourceName = source.Name;
        productCode = source.Product__c;
    }

    private Input_Source__c readSource() {
        Input_Source__c source = [select ID, Name, Product__c
            from Input_Source__c 
            where ID = 'a0G70000004ED4yEAG'];
        return source;
    }

}

Running under Administrator profile a form post works, running under the Customer Portal User profile it throws the error.

Profile access permissions:

Customer Portal User permissions

  • 1
    Are you testing the page through a customer portal per chance ? loading a page through sf/apex/vf_page sometimes gives more detailed error messages. – Samuel De Rycke Jun 13 '13 at 9:48
  • 2
    Does your Site guest user have Profile permissions to save whatever you're saving? Check "Public Access.."-button on the Site config page (1st one). Also if some kind of rollup recalculation occurs or a trigger is at play - he'll need to have edit rights to these impacted objects too. – eyescream Jun 13 '13 at 9:53
  • Good comments! It is a portal page and I get a more detailed error when running it straight under portal user credentials. @eyescream, it is a permission issue, but not sure where to set the permissions. I recently added a new field on the rogue object, but can't seem to edit the permissions on a field after it was created. See my updated error message. – JannieT Jun 13 '13 at 11:09
  • try giving view all and modify all permission for the objects which are used on site using public access settings. – Pankaj Jun 13 '13 at 13:11
7

Site guest user's permissions are stored in "a Profile that can't be accessed as a Profile".

Go to the config page (Setup -> Develop -> Sites) and click "public access settings".

site detail view with button highlighted

You'll see normal Profile edit interface so add rights to objects & fields there.

Why Site "Profiles" aren't listed as normal Profiles - I have no idea. Especially that they can be downloaded to Force.com IDE as *.profile files just fine...

Check what object is required (easiest is to cut first 3 letters from Id so go to https://instance.salesforce.com/a0G) and keep hacking at them?

If you'd get a slightly different error "Insufficient rights on cross reference entity" it might be either sharing related (which I doubt applies for Sites) or you're trying to use a Record Type that's not marked as available for this Site's "profile".

  • Awesome tips in here. Still hunting my bug though. I have set all possible permissions for my Customer Portal User Profile. Essentially I am only updating one row on one object and I have checked that object and it's field permissions. If I run the form as admin I have no problems. I am now going to try and build a very simple page that isolate the problem, and post code if necessary. – JannieT Jun 14 '13 at 6:05
  • @Pankaj suggested it might be something sharing-related. Try flipping your class definition to public without sharing class SomeClassName...? Or grant "modify all" on this object? If this will fix it you'll have to either leave it as is or play with sharing rules. Although I have no idea how to share with an user that really doesn't exist / doesn't have a Role / is not a member of any group. – eyescream Jun 14 '13 at 6:12
  • I see you've edited the question :) All I can do is to "poke" you again to read my comment above. Flip to "without sharing" and if it works - either leave as is or check if you can work sharing rules out to grant rights to edit! What is the "Organisation Wide Default" and are there any sharing rules already on the Input Source? – eyescream Jun 14 '13 at 11:31
  • Thanks for your patient advice. I was reluctant to change to "without sharing", because I don't fully understand the security implications (just that "with sharing" is considered more secure). But, essentially that was it. Flipping my controller to "without sharing" now allows for posting updates. Thanks a lot. – JannieT Jun 14 '13 at 13:49
  • If they're 'guest site users' I think you can't specify sharing rules with them. But if they're Customer Portal-related (as your screenshot suggests) then it should be possible, especially if your Input Source has relationship to the Account they belong to (and even if there's no relationship, maybe you can come up with some criteria-based sharing rule). You're right that's kind of dangerous as your code becomes the only barrier from them obtaining all data from the objects... – eyescream Jun 14 '13 at 13:56

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.