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
EchoEchoEchoEcho 

Very strange system limits exceptions

Hi All,

 

I'm having some very strange problems with SOQL and Collection limits in a VF Controller, but not immediately... sort of cumulatively... or at least after awhile...

 

First off, there's no possible way that there are enough records in the objects that I'm dealing with to go over the 100 query SOQL limit or the 1000 row Collection limit. And yet, at first, I was getting this error:

 

System.Exception: Too many SOQL queries: 101

 

But like I said, not immediately. The class works fine when I test it, and when I deploy it. It will continue to work fine for the next 8 hours or so, while a number of people are happily using it with no problem. And then out of nowhere, I'll get an exception email. So I go look at the VF page, and I get the same error. I've found, after some experimentation, that all I have to do is make some small modification to the controller, like adding a space after a line. I can then re-deploy the class (with no changes made), and the exception will go away for another 8 hours or so.

 

So, I decided to rewrite the class so that there would be no way for this query to get called more than 100 times. Aha! I figured... problem solved. But 8 hours later, I get this email:

 

System.Exception: collection exceeds maximum size: 1001

 

Again, there's no way. There aren't 1001 records in any of these objects. There's like 20 rows getting returned, at most. So, I add a space to the end of a line in the controller, re-deploy, and voila, problem solved. Until tomorrow, at least.

 

Does anybody have any idea what's going on here? Any logical explanation for this? Help?

 

Here's the controller code, if that's helpful at all... this is the second version that I changed so as to avoid getting the first exception. The collection that it's complaining about is List<PhysicianWrapper> physicians.

 

 

public class Customer_Survey_Controller
{
//used for javascript communication
public String selectedPhysiciansString {get; set;}

//the physicians the user has to choose from. Limited by physicians for whom we already have a previous baseline survey.
public List<PhysicianWrapper> availablePhysicians
{
get
{
//generate a list of physician IDs for whom we have a baseline survey
List<PhysicianWrapper> physicians = new List<PhysicianWrapper>();

String idList = '';
Set<String> accountIds = new Set<String>();

for(Contact physicianRecord : [SELECT Id, Name, Account.Id, Account.Name FROM Contact WHERE Id in (SELECT Physician__c FROM Surveys__c) AND Experience_Level__c = 'Experienced Injector' ORDER BY Name])
{
if(physicianRecord.Id != null && physicianRecord.Name != null)
{
//make sure we have no duplicates...
if(physicians.size() == 0 || (physicians.get(physicians.size()-1).physicianRecord.Id != physicianRecord.Id))
{
PhysicianWrapper physicianWrapper = new PhysicianWrapper();
physicianWrapper.physicianRecord = physicianRecord;
physicianWrapper.supportStaff = new List<selectOption>(); //supportStaff(physicianRecord.Account.Id,physicianRecord.Id);
physicians.add(physicianWrapper);

accountIds.add(physicianRecord.Account.Id);
}
}
}

//get the support staff...

for(String accountId : accountIds)
{
idList += '\''+accountId+'\',';
}
idList = idList.substring(0,idList.length()-1);

List<Contact> supportStaffRecords = Database.query('SELECT Id, Name, Role__c, AccountId FROM Contact WHERE AccountId IN ('+idList+') AND Email <> \'\' ORDER BY Name asc');

for(Integer i=0; i<physicians.size();i++)
{
for(Integer j=0; j<supportStaffRecords.size(); j++)
{
if(physicians[i].physicianRecord.Account.Id == supportStaffRecords[j].AccountId)
{
//checkbox id contains both the support staff Id and the pseudo-parent physician Id
//we will send the email to the support staff member, but assign the survey record to the physician
//support.add(new selectOption(supportStaffRecord.Id+','+physicianId,supportStaffRecord.Name));
if(supportStaffRecords[j].Role__c != null)
physicians[i].supportStaff.add(new selectOption('surveyBox,'+supportStaffRecords[j].Id+','+physicians[i].physicianRecord.Id, supportStaffRecords[j].Name+' ('+supportStaffRecords[j].Role__c+')'));
else
physicians[i].supportStaff.add(new selectOption('surveyBox,'+supportStaffRecords[j].Id+','+physicians[i].physicianRecord.Id, supportStaffRecords[j].Name));

}
}
}

return physicians;
}
set;
}

//wrapper class to pass display data to the VF page
class PhysicianWrapper
{
public Contact physicianRecord {get; set;}
public List<selectOption> supportStaff {get; set;}
}

}

 

 

 

 

 

 

Thanks,

Tom 

Message Edited by EchoEcho on 06-03-2009 03:25 PM
Message Edited by EchoEcho on 06-03-2009 03:28 PM