function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fan YangFan Yang 

What's wrong with apex:repeat ?

When using repeat in my visulaforce page as follows, I'm having "Authorization Required" error:

<apex:repeat value="{!MyListData}" var="l">

 <c:MyCustomComponent ... />

</apex:repeat>

if I hard code <c:MyCustomComponent ../>, which works fine. What's wrong? can anybody help? TVM.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Have you ensured that you've given permission to the guest user profile to see the custom objects and fields?

All Answers

saraha@groupesci.comsaraha@groupesci.com

Can you please post your controller/extension code.

 

--Sarah

 

bob_buzzardbob_buzzard

I'm assuming you are using this VF page in a site, as I can't see how else you'd get an authorization required.

 

One thing to be aware of is that you'll end up on the authorization page if an error occurs in your controller, as the standard behaviour is to direct you to a platform error page.  

 

Its worth turning debug logging on to see if there is an error generating your list.

Fan YangFan Yang
My controller code:
public with sharing class SelectPlanController {
	private String state;
	private String utility;
	private String promocode;
	private Map<String, String> mapMDLinks = new Map<String, String>{
		'XX' => 'some0.php',
		'XX2' => 'some1.php',
		'BLAH' => 'some2.php'	};
	private String MDLINK = 'http://www.company.com/appName/';
	private List<Plan__c> plans = new List<Plan__c>();
	
 	public SelectPlanController()
 	{	
 		state = ApexPages.currentPage().getParameters().get('f1');
 		utility = ApexPages.currentPage().getParameters().get('f2');
 		promocode = ApexPages.currentPage().getParameters().get('f3');
 		
 		plans = [select name, planId__c, HasCancelFee__c, PlanPrice__c, PlanTerm__c, PlanSaving__c, UDCCode__c, UDCName__c, state__c, State_Name__c, PriceToCompare__c from plan__c where state__c=:state and Utility__c=:utility];
 		
 	}
 	
 	public List<Plan__c> getAvailablePlans()
 	{
 		return plans;
 	}
 	
 	public PageReference runaway()
 	{
 		PageReference p=null;
 		if( state == 'XX')
 		{
	 		p = new PageReference( MDLINK + mapMDLinks.get(utility));
	 		p.setRedirect(true);
 		} else if( utility == 'YYYY')
 		{
 			p = Page.UtilityNotServed;
 			p.setRedirect(true);
 		}
 		return p;
 	}
}

 My page has:

<apex:repeat value="{!AvailablePlans}" var="p">
  <c:MyCustomComponent pid="{!p.PlanID__c}" .. />
</apex:repead>

 

Fan YangFan Yang

The debugger (monitor) logged:

 

 

16:12:35.705|SOQL_EXECUTE_BEGIN|[20]|Aggregations:0|select name, planId__c, HasCancelFee__c, PlanPrice__c, PlanTerm__c, PlanSaving__c, UDCCode__c, UDCName__c, state__c, State_Name__c, PriceToCompare__c from plan__c where state__c=:state and Utility__c=:utility
16:12:35.710|SOQL_EXECUTE_END|[20]|Rows:2
16:12:35.710|CODE_UNIT_FINISHED|SelectPlanController <init>
16:12:35.711|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008UDv|SelectPlanController invoke(runaway)
16:12:35.711|CODE_UNIT_FINISHED|SelectPlanController invoke(runaway)
16:12:35.711|VF_APEX_CALL|j_id0|{!runaway}|PageReference: none
16:12:35.712|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008UDv|SelectPlanController get(AvailablePlans)
16:12:35.712|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008UDv|SelectPlanController invoke(getAvailablePlans)
16:12:35.712|CODE_UNIT_FINISHED|SelectPlanController invoke(getAvailablePlans)
16:12:35.712|CODE_UNIT_FINISHED|SelectPlanController get(AvailablePlans)
16:12:35.782|CUMULATIVE_LIMIT_USAGE
16:12:35.782|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 2 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
  Number of script statements: 14 out of 200000
  Maximum heap size: 0 out of 3000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

16:12:35.782|CUMULATIVE_LIMIT_USAGE_END

16:12:35.741|CODE_UNIT_FINISHED|VF: /apex/SelectPlan
16:12:35.741|EXECUTION_FINISHED
Fan YangFan Yang

in system log window:

 

List<Plan__c> plans = [select name, planId__c, HasCancelFee__c, PlanPrice__c, PlanTerm__c, PlanSaving__c, UDCCode__c, UDCName__c, state__c, State_Name__c, PriceToCompare__c from plan__c];

for(Plan__c p : plans)
{
    System.Debug('planID=' + p.PlanID__c + '; fixedPrice=' + p.PlanPrice__c + '; planSavings=' + p.PlanSaving__c + '; priceToCompare=' + p.PriceToCompare__c + '; stateName=' + p.State_Name__c +  '; planName=' + p.Name + '; hasCancelFee=' + p.HasCancelFee__c + '; term=' + p.PlanTerm__c + '; udcCode=' + p.UDCCode__c);
}

Which works fine; however put them into visualforce page: 

 

<table border="0" >
        <tr>
            <th>Name</th><th>ID</th>
            <th>Has Cancel Fee</th><th>Status</th>
            <th>Term</th><th>Saving</th><th>UDC Code</th>
            <th>UDC Name</th><th>State</th><th>State Name</th><th>Price to Compare</th>
        </tr>
        <apex:repeat var="p" value="{!availablePlans}" id="dynamicContent">
        <tr>
            <td>{!p.Name}</td>
            <td>{!p.PlanID__c}</td>
            <td>{!p.HasCancelFee__c}</td>
            <td>{!p.PlanPrice__c}</td>
            <td>{!p.PlanTerm__c}</td>
            <td>{!p.PlanSaving__c}</td>
            <td>{!p.UDCCode__c}</td>
            <td>{!p.UDCName__c}</td>
            <td>{!p.State__c}</td>
            <td>{!p.State_Name__c}</td><td>{!p.PriceToCompare__c}</td>
        </tr>

        </apex:repeat> 

    </table>

Empty table shows up, #of empty rows matched #of records; but all td are empty; what could be wrong? 

 

 

bob_buzzardbob_buzzard

Are you running the Visualforce as the same user that you are executing the code in the system log?

 

Also, your controller is declared as "with sharing", which means that you won't be able to see records that haven't been shared with you.  When you run this is the system log, it will be without sharing which will show you everything.

 

Try changing your controller declaration to:

 

 

public without sharing class SelectPlanController {

 and see if that helps.

 

Fan YangFan Yang

Yes, I used same use to execute the code in system log.  I tried "without", which didn't help. Here are the monitor log (created for Site Guest user). You can see the there are correct row count returned. BTW, how to "share" my custom object in VF? Thanks!!

 

 

14:37:45.060|EXECUTION_STARTED
14:37:45.061|CODE_UNIT_STARTED|[EXTERNAL]|066E000000006RC|VF: /apex/TestRepeat
14:37:45.128|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008WUy|ListDataController <init>
14:37:45.128|CODE_UNIT_FINISHED|ListDataController <init>
14:37:45.129|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008WUy|ListDataController get(ListData)
14:37:45.129|CODE_UNIT_STARTED|[EXTERNAL]|01pE00000008WUy|ListDataController invoke(getListData)
14:37:45.129|METHOD_ENTRY|[1]|01pE00000008WUy|ListDataController.ListDataController()
14:37:45.129|METHOD_EXIT|[1]|ListDataController
14:37:45.130|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select name, planId__c, HasCancelFee__c, PlanPrice__c, PlanTerm__c, PlanSaving__c, UDCCode__c, UDCName__c, StateAbbr__c, State_Name__c, PriceToCompare__c from plan__c WHERE StateAbbr__c='NJ'
14:37:45.137|SOQL_EXECUTE_END|[4]|Rows:4
14:37:45.137|CODE_UNIT_FINISHED|ListDataController invoke(getListData)
14:37:45.137|CODE_UNIT_FINISHED|ListDataController get(ListData)
14:37:45.284|CUMULATIVE_LIMIT_USAGE
14:37:45.284|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 4 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
Number of script statements: 2 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

14:37:45.284|CUMULATIVE_LIMIT_USAGE_END

14:37:45.153|CODE_UNIT_FINISHED|VF: /apex/TestRepeat
14:37:45.153|EXECUTION_FINISHED

 

 

bob_buzzardbob_buzzard

Have you ensured that you've given permission to the guest user profile to see the custom objects and fields?

This was selected as the best answer
Fan YangFan Yang

It  must be permission issue. How to grant "Site guest users" permission to Read or Write my custom object?

Fan YangFan Yang

Figured out how to grant guest user RO permission to my custom object from the wiki: http://wiki.developerforce.com/index.php/Authenticating_Users_on_Force.com_Sites. TVM, Bob!!

bob_buzzardbob_buzzard

Unfortunately you can't access the site guest profile through the regular profile setup pages.  

 

On your site configuration page, there is a button entitled 'Public Access Settings'.  If you click that it will take you through to the profile.