+ Start a Discussion
SF Admin.HRGSF Admin.HRG 

Visualforce page controller not allowing lookups?

Hi

We've got a VS page which is going to be used on a public Site. It's accessible for the custom object it was created for.

However there is also a lookup to Account object and this is where the issues begin. 

We need the site URL to be able to include Account ID as a part of it (randomUrl.com/randomID) which would be read in as the input for this Account ID lookup field. 

However currently it's not even displaying the page if anything related to Account is added to site's controller extension. It requests authorization, even though Guest User has been given access to Account and Custom Object. 

What is missing? 

public with sharing class myControllerTest 
{
    public Feedback_Form__c feedback {get;set;}
    public Account account {get; set;}
        
    public myControllerTest(ApexPages.StandardController controller) 
    {
    
    Id accountId = apexpages.currentpage().getparameters().get('id');
    account = [SELECT Id, Name FROM Account WHERE Id =: accountId]; 
    
     feedback = new Feedback_Form__c();
     feedback.Account__c = account.Id;
    }
    public void submit() 
    {
        System.Debug('FEEDBACK: ' + feedback);
    }
}
Best Answer chosen by SF Admin.HRG
bob_buzzardbob_buzzard
You could have an exception there that is being swallowed - I've found that VF can lose exceptions that are thrown from a constructor. Try putting an exception handler around it and see if that shows anything, e.g. :
 
public myControllerTest(ApexPages.StandardController controller) 
    {
    
      try
      {
          Id accountId = apexpages.currentpage().getparameters().get('id');
          account = [SELECT Id, Name FROM Account WHERE Id =: accountId]; 
    
          feedback = new Feedback_Form__c();
          feedback.Account__c = account.Id;
          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Got account with id ' + account.Id);       
      }
      catch (Exception e)
      {
          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
      }
    }

You'll need an apex:pageMessages component on the page to see the message.