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
Newbie_edmNewbie_edm 

Apex code not working if record count goes more than 3000

Hi Guys,

My code works in sandbox and production with litter data but not loading calendar when record count goes more than 3000. any thoughts?


my apex code

public class ColoredCalendar {

 public string myProperty {get; set;}
 public string myview {get; set;}
 public string theValue {get; set;}
public static List<String> values {get; set;}
public String positions {get; set;}
public  String selectedLocation{get; set;}
public Boolean includeMyEvents {get;set;}
    public list<calEvent> events {get;set;}
  

    //The calendar plugin is expecting dates is a certain format. We can use this string to get it formated correctly
    String dtFormat = 'EEE, d MMM yyyy HH:mm:ss z';

    //constructor
    public ColoredCalendar () {
        //Default showing my events to on
        includeMyEvents = true;
       
    }


       

 
 
        
        public List<SelectOption> getItems() {
        
         
         string ownerid=ApexPages.currentPage().getParameters().get('ownerid');
          events = new list<calEvent>();
             user loginuser =[select id,TimeZoneSidKey  from user where id=:ownerid];

            List<SelectOption> options = new List<SelectOption>();

                        Set<String> locationName = new Set<String>();
                        
                         

                    for (Event e : [SELECT Location FROM Event where ownerid=:ownerid limit 9999])
                            {
                              if(e.location!=null){
                              locationName.add(e.location); // contains distict accounts
                              }
                            }
 
            options.add(new selectOption('', '- None -'));
            
            for (String s : locationName)
             {
                
                options.add(new selectOption(s, s));
             }
         
            return options;

        }
          


    public PageReference pageLoad() {
    
                        if(myProperty == null){
                    myview ='month';
                    }
                   if(myProperty == 'agendaWeek'){
                    myview ='agendaWeek';
                    }
                   if(myProperty == 'agendaDay'){
                    myview ='agendaDay';
                    }               
                    if(myProperty == 'month'){
                    myview ='month';
                    }
                    
                    System.Debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The myview value is : ' + myview);
                   System.Debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The myProperty value is : ' + myProperty);
    
        string ownerid=ApexPages.currentPage().getParameters().get('ownerid');
        events = new list<calEvent>();
             user loginuser =[select id,TimeZoneSidKey  from user where id=:ownerid];
          //Get my Events if we hrave selected the correct option
        
          String query ='select Id, Subject, isAllDayEvent, StartDateTime, EndDateTime, Location from Event where id!=NULL';
          if(ownerid!=null)
          {
             query+= ' AND ownerid=:ownerid';
             
          }
          
         if(selectedLocation !=null )
          {
             query+= ' AND Location=:selectedLocation';
             
          }
          
          List<SObject>  resultSet = Database.query(query);
          
          
          
            for(SObject evnt: resultSet){
                 

                DateTime startDT = (datetime)evnt.get('StartDateTime');
                DateTime endDT = (datetime)evnt.get('EndDateTime');
                calEvent myEvent = new calEvent();

                myEvent.title = (String)evnt.get('Subject');
                myEvent.allDay = (boolean)evnt.get('isAllDayEvent');
                myEvent.location = (String)evnt.get('Location');
                myEvent.startString = convertdatetime(startDT,loginuser.TimeZoneSidKey  ).format();
                myEvent.endString = convertdatetime(endDT ,loginuser.TimeZoneSidKey  ).format();
                 String[] parts1 =  myEvent.startString.split(' ');
                   String[] parts2 =  myEvent.endString .split(' ');
                   myEvent.starttime=parts1 [1];
                   myEvent.endtime =parts2[1];
                   
    //system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + myEvent.location.indexOf('[B]'));
        //        String str = myEvent.location;
       //         if(myEvent.location.indexOf('[B]')!=-1)
       //         {
       
     //   myEvent.className = 'classB';
     //   system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' +str);
        system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' +myEvent.location);
      //          }
    
    
                    
                

  
                   
           //  if(Location_substr.containsOnly('A]'))
             //   {
            //          myEvent.className = 'classA';
                      
             //  }
            //  
            

              if(myEvent.location!=null){
            
                  if(myEvent.location.indexOf('[A]')!=-1)
                  {
                        myEvent.className = 'classA';
                  }
                  if(myEvent.location.indexOf('[B]')!=-1)
                  {
                        myEvent.className = 'classB';
                  }
                  if(myEvent.location.indexOf('[C]')!=-1)
                  {
                        myEvent.className = 'classC';
                  }
                  if(myEvent.location.indexOf('[D]')!=-1)
                  {
                        myEvent.className = 'classD';
                  }
                  if(myEvent.location.indexOf('[E]')!=-1)
                  {
                        myEvent.className = 'classE';
                  }
                  if(myEvent.location.indexOf('[F]')!=-1)
                  {
                        myEvent.className = 'classF';
                  }
                 if(myEvent.location.indexOf('[G]')!=-1)
                  {
                        myEvent.className = 'classG';
                  }
                  
                  if(myEvent.location.indexOf('[H]')!=-1)
                  {
                        myEvent.className = 'classH';
                  }
                  if(myEvent.location.indexOf('[I]')!=-1)
                  {
                        myEvent.className = 'classI';
                  }
                  if(myEvent.location.indexOf('[J]')!=-1)
                  {
                        myEvent.className = 'classJ';
                  }    

                                      
              }else
              {
                     myEvent.className = 'classK';
              
              }
               events.add(myEvent);
      
          
                 
            }
            
    // System.Debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The value is theValue : ' + theValue);
               //   System.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4VARIABLE MYPROPERTY------' + myProperty);


        return null;
    }

  /*  public PageReference toggleMyEvents() {
        if(includeMyEvents){
            includeMyEvents = false;
        }
        else{
            includeMyEvents = true;
        }
        pageload();
        
        return null;
    } */
    
    
    public datetime convertdatetime(datetime getdatetime, string ownerZoneKey)
    {
        TimeZone OwnerTimZone= TimeZone.getTimeZone(ownerZoneKey);
        integer owner_Offest= OwnerTimZone.getOffset(getdatetime);

       TimeZone LoginuserTimeZone= UserInfo.getTimeZone();
        integer Loginuser= LoginuserTimeZone.getOffset(getdatetime);
           integer diff = owner_Offest-Loginuser;
       return     getdatetime.addMinutes(diff /(1000 * 60));

    }

    //Class to hold calendar event data
    public class calEvent{
        public String title {get;set;}
        public Boolean allDay {get;set;}
        public String location {get;set;}
        public String startString {get;set;}
        public String endString {get;set;}
        public String url {get;set;}
        public String className {get;set;}
        public string starttime{get;set;}
        public string endtime {get;set;}
        public string countries {get;set;}
        public string color {get;set;}
        public string theValue {get; set;}
       
    }
}

VF page code.

<apex:page showHeader="false" controller="V_CalendarController1" action="{!pageLoad}" readOnly="true">
    <link href="{!URLFOR($Resource.fullcalendar,'fullcalendar/fullcalendar.css')}" rel="stylesheet" />
    <link href="{!URLFOR($Resource.fullcalendar,'fullcalendar/fullcalendar.print.css')}" rel="stylesheet" media="print" />
     
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="{!URLFOR($Resource.fullcalendar,'fullcalendar/fullcalendar.min.js')}"></script>
    
       
 <apex:outputPanel id="calPanel">
   
    <script>
   
        //We need to wrap everything in a doc.ready function so that the code fires after the DOM is loaded
        
      $(document).ready(function() {   
            //Call the fullCallendar method. You can replace the '#calendar' with the ID of the dom element where you want the calendar to go. 
            $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next Month,today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'

                    
                }, 
                


                
                editable: false,
                
                minTime: '06:00:00',
                maxTime: '22:00:00',
                slotEventOverlap: false,
 
     
                events:
                [
                    //At run time, this APEX Repeat will reneder the array elements for the events array
                              
                               
                    <apex:repeat value="{!events}" var="e" id="scannersDiv">
                      
                        {
                            title: "{!e.starttime} - {!e.endtime} | {!e.title} | {!e.location}",
                            start: '{!e.startString}',
                            end: '{!e.endString}',
                            url: '{!e.url}',
                            allDay: {!e.allDay},
                            className: '{!e.className}'

                       

                        },
                       
                    </apex:repeat> 
                   
   
                ]
                
                
                
                

       });
            

        
      

      
        });
               
   //auto scrolls down to current day
            var d = new Date();
            var day = d.getDate();
            $('html, body').animate({
            scrollTop: $('.fc-day-number:contains("'+day+'")').offset().top
            }, 1000);
            
 
      
</script>
  
    <!--some styling. Modify this to fit your needs -->
    <style>
         #cal-options {float:left;}
        #cal-legend { float:right;}
        #cal-legend ul {margin:0;padding:0;list-style:none;}
        #cal-legend ul li {margin:0;padding:5px;float:left;}
        #cal-legend ul li span {display:block; height:16px; width:16px; margin-right:4px; float:left; border-radius:4px;}
        #calendar {margin-top:20px;}
        #calendar a:hover {color:#fff !important;}
         
        .fc-event-inner {padding:3px;}
        .event-birthday {background:#56458c;border-color:#56458c;}
        .event-campaign {background:#cc9933;border-color:#cc9933;}
       .classA {background:#8A6CE4;border-color:#eac2c8;text-color:#FFFFFF;}
       .classB {background:#6BD459; border-color:#56BF44; text-color:#FFFFFF;}
       .classC {background:#54B3E2; border-color:#42A1D0; text-color:#FFFFFF;}
       .classD {background:#54B3E2; border-color:#42A1D0; text-color:#FFFFFF;}
       .classE {background:#E8D14E; border-color:#DAC134; text-color:#FFFFFF;}
       .classF {background:#d1d6ef; border-color:#c2c8ea; text-color:#000000;}
       .classG {background:#c8eac2; border-color:#bbe5b3; text-color:#000000;}
       .classH {background:#efd1d6; border-color:#eac2c8; text-color:#000000;}
       .classI {background:#d1e5ef; border-color:#b3d4e5; text-color:#000000;}
       .classJ {background:#eae4c2; border-color:#e5ddb3; text-color:#000000;}

        .fc-event-inner {width:98%;}
        .fc-event-time {display:none;}
 
    
        
        
    </style> 

<apex:form >
<table align="center">
            <tr>  
            <td> <b> Select Location </b></td>  
            <td> <apex:selectList value="{!selectedLocation}"  size="1" id="test">
            <apex:actionSupport event="onchange"  action="{!pageLoad}"/>
                       <apex:selectOptions Value="{!items}">
                               
                             
                 
                              </apex:selectOptions>
                          </apex:selectList>  </td>

            </tr>

</table>

</apex:form>
   
        <!-- my code End -->  
            <div id="cal-legend">
                <ul>

                   <!-- <li style="{!IF(includeMyEvents,'','display:none')}"><span class="event-personal"></span>My Events</li-->
                </ul>
                <div style="clear:both;"><!--fix floats--></div>
            </div>
            <div style="clear:both;"><!--fix floats--></div>
            <div style="border:0px solid red;padding:10px;">
            <div id="calendar"></div>
            </div> 
 </apex:outputPanel> 
         
</apex:page>