+ Start a Discussion
Victor van Dijk 2Victor van Dijk 2 

Getting 'unauthorized' page for long running public VF page.

I created a public force.com site and added a VF page called 'download'. I can open this page from a browser as an anonymous user. But in some cases, a user gets the default 'unauthorised' page.

This works fine: https://letterenfonds.secure.force.com/vertalingendatabase/download?languageCode=en&taal=Bulgaars&type=search&query=

This doesn't https://letterenfonds.secure.force.com/vertalingendatabase/download?languageCode=en&taal=Duits&type=search&query (https://letterenfonds.secure.force.com/vertalingendatabase/download?languageCode=en&taal=Duits&type=search&query)=

There are more German books in the datase compared to the Bulgarian ones, so I expect the problem to be caused by the number of results. The debug log does not give a clue that the user is being forwarded to the unautorized page.

31.0 APEX_CODE,INFO;APEX_PROFILING,FINEST;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,FINER;WORKFLOW,INFO
11:41:19.029 (29147173)|EXECUTION_STARTED
11:41:19.029 (29188955)|CODE_UNIT_STARTED|[EXTERNAL]|066b0000001Re3o|VF: /apex/download
11:41:19.044 (44800885)|CODE_UNIT_STARTED|[EXTERNAL]|01pb0000004VFVA|PageLanguageController <init>
11:41:19.066 (66093101)|CODE_UNIT_FINISHED|PageLanguageController <init>
11:41:19.066 (66138583)|CODE_UNIT_STARTED|[EXTERNAL]|01pb0000004VFVA|PageLanguageController get(requestLanguage)
11:41:19.066 (66159994)|CODE_UNIT_STARTED|[EXTERNAL]|01pb0000004VFVA|PageLanguageController invoke(getrequestLanguage)
11:41:19.066 (66219490)|CODE_UNIT_FINISHED|PageLanguageController invoke(getrequestLanguage)
11:41:19.066 (66229172)|CODE_UNIT_FINISHED|PageLanguageController get(requestLanguage)
11:41:19.096 (96463483)|CODE_UNIT_STARTED|[EXTERNAL]|01pb0000004VFV2|DownloadController <init>
11:41:19.124 (124120595)|SOQL_EXECUTE_BEGIN|[84]|Aggregations:0|SELECT COUNT_DISTINCT(Id) totalResults FROM Titel__c WHERE isZichtbaar__c = true AND isVertaling__c = true AND Taal__c  =  'Duits'
11:41:19.286 (286629508)|SOQL_EXECUTE_END|[84]|Rows:1
11:41:19.311 (311909509)|SOQL_EXECUTE_BEGIN|[46]|Aggregations:0|SELECT Id,Zoekresultaat_NL__c FROM Titel__c WHERE isZichtbaar__c = true AND isVertaling__c = true AND Taal__c  =  'Duits' ORDER BY Sorteernaam_Oorspronke__c, Taal__c, Titel__c, Publicatiedatum__c ASC NULLS LAST
11:41:30.419 (11419051984)|SOQL_EXECUTE_END|[46]|Rows:5000
*** Skipped 4598855 bytes of detailed log
...
11:41:32.071|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 10000 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 1709 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10
...
11:41:32.071|CUMULATIVE_LIMIT_USAGE_END

11:41:32.091|CUMULATIVE_PROFILING_BEGIN
11:41:32.091|CUMULATIVE_PROFILING|SOQL operations|
Class.FreeSearchRestService.doInternalSearch: line 46, column 1: Database.query(String): executed 1 time in 11114 ms
Class.FreeSearchRestService.getResultCountSOQL: line 84, column 1: Database.query(String): executed 1 time in 165 ms

11:41:32.091|CUMULATIVE_PROFILING|No profiling information for SOSL operations
11:41:32.091|CUMULATIVE_PROFILING|No profiling information for DML operations
11:41:32.091|CUMULATIVE_PROFILING|method invocations|
Class.DownloadController.<init>: line 10, column 1: private JSONDetailedOutputWrapper executeSearch(SearchQueryParameters): executed 1 time in 12470 ms
Class.DownloadController.executeSearch: line 39, column 1: public String __sfdc_query(): executed 13 times in 12461 ms
Class.FreeSearchRestService.doInternalSearch: line 49, column 1: public static String getSummaryFieldName(String): executed 10000 times in 308 ms
Class.FreeSearchRestService.doInternalSearch: line 51, column 1: public JSONOutputWrapper(String, String): executed 10000 times in 190 ms
Class.FreeSearchRestService.doInternalSearch: line 39, column 1: private static Integer getResultCountSOQL(String, String, String, String, String, String, String, String): executed 1 time in 172 ms
Class.FreeSearchRestService.doInternalSearch: line 42, column 1: public static String getSummaryFieldName(String): executed 1 time in 24 ms
Class.FreeSearchRestService.doInternalSearch: line 48, column 1: global public system.Iterator iterator(): executed 5002 times in 16 ms
Class.JSONOutputWrapper.<init>: line 16, column 1: public void __sfdc_id(String): executed 5000 times in 16 ms
Class.SearchOptionQueryBuilder.getSummaryFieldName: line 25, column 1: public static Boolean isEmpty(String): executed 10002 times in 15 ms
Class.JSONOutputWrapper.<init>: line 17, column 1: public void __sfdc_text(String): executed 5000 times in 5 ms
Class.FreeSearchRestService.doInternalSearch: line 50, column 1: public static Boolean isEmpty(String): executed 5000 times in 3 ms

11:41:32.091|CUMULATIVE_PROFILING_END
11:41:31.584 (12584158465)|CODE_UNIT_FINISHED|VF: /apex/download
11:41:31.585 (12585418733)|EXECUTION_FINISHED


 
Sagar PareekSagar Pareek
Have you tried limiting your query results using LIMIT clause in SOQL? Do that solves the issue? 
Ramesh KosalairamanRamesh Kosalairaman
Hi 

Try filed or object permission for the related object
Victor van Dijk 2Victor van Dijk 2
Limiting the resultset to +/- 1200 in the DEV sandbox makes the page work again. But this will make it impossible to download the entire set of titles. The question is: why is the unauthorized page shown and why is the logging not showing this.
Sagar PareekSagar Pareek
If you try opening page within salesforce do any error comes such as Collection size exceeded?
Victor van Dijk 2Victor van Dijk 2
Adding readOnly="true" to the <apex:page..> tag solved the problem. 500 results are returned without breaking the page.

This caused the following:
Class.FreeSearchRestService.doInternalSearch: line 46, column 1: Database.query(String): executed 1 time in 9721 ms (from 11114 ms)

Fixed for now but not feeling too comfortable with this fix.
Victor van Dijk 2Victor van Dijk 2
A small typo: 5000 items are returned. This appears to be the limit for soql. This is expected behaviour.
There was no problem with collection size. The SOQLSOSL timings were the only problem I could find. If these are a problem, I cannot understand why the not autorized page is shown. There's a limit exceeded page that is more suitable for this kind of problems.