1

I have created a Force.com site but I can't access a page with it.

I am getting the error below: enter image description here

VF Page

<apex:page standardcontroller="Case" extensions="CActions" showHeader="false" sidebar="false" applyBodyTag="false" docType="html-5.0">
    TEST
</apex:page>

Apex Controller

global class CActions {
    public Case caseObj {get; set;}

    public CActions(ApexPages.StandardController controller) {
        if(controller.getRecord() != null) {
            caseObj = [SELECT Id, Type
                       FROM Case
                       WHERE Id = :controller.getRecord().Id];
        }   
   }
}

Few checks that I have done :

  • The VF page is set as Active Site Home Page on the site.
  • Yes, the page is in the Site Visualforce Pages list.
  • Access has been granted on the Apex class via Public Access Settings.
  • Case object has Read access.
  • Read and Edit rights added on field Type.

If I remove

if(controller.getRecord() != null) {
    caseObj = [SELECT Id, Type
               FROM Case
               WHERE Id = :controller.getRecord().Id];
}

, the page works fine on the Force.com site. enter image description here

Note:

Page works great using .../apex/VFP_Test?id=500N0000004c8ts

Does not work with the Force.com site URL : https:// scrmtest.cs6.force.com/VFP_Test?id=500N0000004c8ts

Tried debugging but no luck:

  • System.debug('## controller record : ' + controller );

gives me

|USER_DEBUG|[23]|DEBUG|## controller record : ApexPages.StandardController[Case]

  • System.debug('## controller record : ' + (Case)controller.getRecord() ); does not even appear in the log.

Any issue with my code/settings?

Update : Still need help with this one.

1

You can solve your problem by using below class code:

   global class CActions {
        public Case caseObj {get; set;}
        public CActions(ApexPages.StandardController controller) {
            caseObj =(Case)controller.getRecord();
            if(caseObj != null && caseObj.Id!=null) {
                caseObj = [SELECT Id, Type
                           FROM Case
                           WHERE Id = :caseObj.Id];
            }   
       }

}

There are access issues faced with sObjects in force.com sites and controller.getRecord() returns a sObject. So we can resolve issue by casting it to a Case object.

  • Tried it. But not working unfortunately. :( I am still getting 'Authorization Required' page. – N.. Feb 2 '17 at 11:58
  • Added a null check for id and now it will work. Make sure a id is passed to site url as {Site URL}?id=<validCaseId> – Mukesh Verma Feb 2 '17 at 12:15
  • Check that your page is available to the Site Guest User profile, see help.salesforce.com/… – Troy Feb 2 '17 at 12:20
  • @MukeshVerma, it is still not working. I am passing a valid Case Id in URL. My url = < https:// scrmtest.cs6.force.com/VFP_Test?id=500N0000004c8ts >. Note : space after // added on purpose above, to be able to post full link here. – N.. Feb 2 '17 at 12:23
  • @Troy, yes it is available. Else, I would not have got 'Test' when I remove the 'if' condition in the class, as mentioned in question. See screen shot attached in my question. – N.. Feb 2 '17 at 12:25
1

I don't know why getRecord() is not working with force.com site.

But I got my page to work with the following workaround:

I have used the parameter id and have queried the Case.

public CActions(ApexPages.StandardController controller) {
    //System.debug('## controller : ' + controller);
    //System.debug('## controller get record : ' + (Case) controller.getRecord() );

    caseId = ApexPages.currentPage().getParameters().get('id');

    System.debug('## caseId : ' +caseId);

    caseObj = [SELECT Id, Type
               FROM Case
               WHERE Id = :caseId];

    System.debug('## caseObj: ' + caseObj);
}

Anyone who run into this issue may use the above.

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.