+ Start a Discussion

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';

    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])
                              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';
             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';
             //  }

                        myEvent.className = 'classA';
                        myEvent.className = 'classB';
                        myEvent.className = 'classC';
                        myEvent.className = 'classD';
                        myEvent.className = 'classE';
                        myEvent.className = 'classF';
                        myEvent.className = 'classG';
                        myEvent.className = 'classH';
                        myEvent.className = 'classI';
                        myEvent.className = 'classJ';

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

        return null;

  /*  public PageReference toggleMyEvents() {
            includeMyEvents = false;
            includeMyEvents = true;
        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">
        //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. 
                header: {
                    left: 'prev,next Month,today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'


                editable: false,
                minTime: '06:00:00',
                maxTime: '22:00:00',
                slotEventOverlap: false,
                    //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}'





   //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);
    <!--some styling. Modify this to fit your needs -->
         #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;}

<apex:form >
<table align="center">
            <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:selectList>  </td>



        <!-- my code End -->  
            <div id="cal-legend">

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