+ Start a Discussion
Chris987654321Chris987654321 

Really confused...Rerender causes insufficent priveldges

I am noticing a very strange problem. On my page I have a <apex:selectList> with a rerender actionsupport method that calls campusChanged() that happens on the onChange event.

 

For some reason when I change the value in the selectList, I get an Insufficient Priveldges message. This was working yesterday but now does not work since I have added some code. But now I have commented out much of the code and it still happens. It happens when I use with sharing or not. It even happens when I am logged in as a System Administrator. I commented so much out that the rerender just calls campusChanged() and all that does is send a debug message. So I am really confused.

 

I checked the debug logs and when I change the select list it does not even get to my System.debug() call.

 

 

public with sharing class DOAReportController {
    public DOAReportController() {
        
        selectedCampus = campuses[0].getValue();
        
        distinctOppOwnersSet = new Set<String>();
        
        distinctOppOwners = [SELECT OwnerID FROM Opportunity GROUP BY OwnerID];
       
		for (AggregateResult ar : distinctOppOwners) {
			System.debug('OwnerID: '+ar.get('OwnerID') );
			distinctOppOwnersSet.add(ar.get('OwnerID')+'');
			
		}
		
		opportunities = [select Id, OwnerID, CreatedDate, AccountID FROM Opportunity];
        
        getCampusContacts();
       
       

    }
    
    private Opportunity [] opportunities;
    private AggregateResult[] distinctOppOwners;
    private Campus_Contacts__c [] campusContacts;
    private Map <Id, Id> oppIdToOwner;
    private Map <String, Id> userIdToName;
    private Set<String> distinctOppOwnersSet;
    
    public String weeklyAppointments { get; set; }

    public String HitRate { get; set; }

    public String SuccessfulCalls { get; set; }

    public String calls { get; set; }

    public String contactPercent { get; set; }

    public String numberOfUnContactedLeads { get; set; }

    public List<SelectOption> campuses {
        get {
            
            Account [] campus = [Select Id, Name FROM Account];
            List<SelectOption> options = new List<SelectOption>();
            
            for (Account a:campus) {
                options.add(new SelectOption(a.Id,a.Name));
            } 
            System.debug ('----- Options size ' + options.size());
            return options;
        }
        
        set;        
    }
    
    public string selectedCampus {get; set;}
    
    public List <string> nameOfReps;
    
    public void campusChanged(){
    	//campusContacts = null;  
    	System.debug('--- Selected Campus = '+selectedCampus);	
        //getNameOfReps();
        //getnumberOfLeads();
    }
    
    
    
    private void getCampusContacts() {
    	//Get the names of employees that are of the title 'Program Manager / Admissions Representative' 
    	//and are associated with the selected campus
    	campusContacts = [select Employee__r.Id, Organization__c, TItle__c, Employee__r.Name 
	                        FROM Campus_Contacts__c
	                        WHERE TItle__c = 'Program Manager / Admissions Representative' 
	                        AND Employee__r.isActive = true                 
	                        ];
        
    }
    
    public List<string> getNameOfReps() {           
        List <string> repNames = new List <string>();   
        /*
        
        if (campusContacts==null)
        	getCampusContacts();
        
        //and the names to the reNames list to display on the report
        for (Campus_Contacts__c c:campusContacts)   {
            if (c.Organization__c == selectedCampus) {        		
        	
        		repNames.add(c.Employee__r.Name);
            }
        }   
        */                
        return repNames;
    }
    
    public List <Integer> numberOfLeads;
    
    public List <Integer> getnumberOfLeads() {        
    	Date dateRangeStart = Date.newInstance(2010, 1, 1);
    	Date dateRangeEnd = Date.newInstance(2010, 4, 31);
    		
        //if (campusContacts==null)
        //	getCampusContacts();
        
        List <Integer> numLeads = new List <Integer>();
        /*
        Integer count = 0;	        
        
        for (Campus_Contacts__c c : campusContacts) {
        	 if (c.Organization__c == selectedCampus) {   
            	count = 0;
            	if (distinctOppOwnersSet.contains(c.Employee__r.Id+'')){
            		//figure out how many opps that rep owns
            		for (Opportunity o : opportunities) {
	        			if (o.ownerId == c.Employee__r.Id) {
	        				
	        				Date oppCreateDate = Date.newInstance(o.CreatedDate.year(), o.CreatedDate.month(), o.CreatedDate.day());
	        				
	        				if (oppCreateDate >= dateRangeStart &&
	        					oppCreateDate <= dateRangeEnd) {
	        						count++;
	        					}
	        			}
	        		
	       			}
	       			numLeads.add(count);	
            	}
            	
            	else {
            		//if the distinct owner list does not have the rep's id then place a 0 and move on
            		numLeads.add(0);
            		continue;
            	}
        	}
        }
        */
        numLeads.add(0);numLeads.add(0);numLeads.add(0);
        return numLeads;
	}
        
    
}

 

 

 

 

 

<apex:page controller="DOAReportController" >
    <apex:form >            
        
        <apex:selectList value="{!selectedCampus}" multiselect="false" size="1">
            <apex:selectOptions value="{!campuses}"/>
            <apex:actionSupport event="onchange" action="{!campusChanged}" 
                                            immediate="false" rerender="LastWeek"/>
        </apex:selectList>
        <br/><br/>
        <apex:outputPanel id="LastWeek">
            <table border="1" width="100%">
                <!-- Names of Reps -->
                
                
                
                
            </table>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 

 

 

SteveBowerSteveBower

Hi, without spending much time on this one thing that looks odd to me (unless I'm missing something) is your use of ...

 

selectedCampus = campuses[0].getValue();

 

... when the controller is instantiated.    The get method for the campuses list hasn't been called yet and so I'm not sure what's actually going on there.   I'm sort of surprised that you don't have an error right there.   Perhaps that's doing something wierd when you go and try to use "selectedCampus"?

 

Another suggestion, unrelated to your problem, you probably don't want to requery all the Accounts in your system each time you refresh the page.  Your getCampuses() code might want to first check to see if campuses.isEmpty() and only do the query to build the list of selectOptions if it's needed the first time.    (Or, build the List in the controller and just return the pre-built list in the getter.)  

 

Curious as to what you discover...., Best, Steve.

 

selectedCampus = campuses[0].getValue();
Chris987654321Chris987654321

I commented out this line but no luck. So the constructor gets called again when you do a rerender of an element on a page? I didn't know for sure if it did.

selectedCampus = campuses[0].getValue();
SteveBowerSteveBower

The constructor is just instantiated once when the page loads.

 

Sorry, I'm not sure what's giving you the problem.  I'd see if the debug logs have anything useful (although I'm sure you've done that already), and then try breaking down the problem.

 

Perhaps just create a simple commandbutton which calls that action and see what happens when you call it directly.  Then try getting rid of the rerender, perhaps there's something there? 

 

 

Hmmmm.   When I define actions I have them returning a pageReference instead of  a void.  I'd see if this helps:

    public pageReference campusChanged(){
campusContacts = null;
System.debug('--- Selected Campus = '+selectedCampus);
return null;
}

 

You don't really need to do the getNameOfReps() and getnumberOfLeads() calls here in this action.  You really only need the new values in those arrays when their getters are called, so why not just let the getters be called normally instead of doing that duplicate call here. 

 

Curious to see what you find, Steve

 

 

 

    public void campusChanged(){
//campusContacts = null;
System.debug('--- Selected Campus = '+selectedCampus);
//getNameOfReps();
//getnumberOfLeads();
}