+ Start a Discussion
ChermaduraiChermadurai 

How to Schedule Class

 

Hello,

 

 

global class ApexScheduledClass Implements Schedulable
            {
                       global void execute(SchedulableContext sc)
                        {
                                    ValAdd();
                        }
 public  static void ValAdd()
  { 
 
List<FBR_Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from FBR_Inquiry__c  ];
{
FBR_Inquiry__c FBR= Inquiry[0];
Date startDate=FBR.ModifyDate__c.toStartOfMonth();
Date endDate=FBR.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from FBR_Inquiry__c where KPIInquiryContent__r.Account__c=:FBR.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('dry' ,'dfjgfj')];

LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:FBR.KPIInquiryContent__r.Account__c];

List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where  Account_Name__c=:FBR.KPIInquiryContent__r.Account__c and Date__c >= :startDate and Date__c < :endDate];
if(!acc.isEmpty() )
      {
         
          KPIAccident__c accupdate = acc[0];        
          Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));
         
          accupdate.MonthlyGeneratedCount__c=totalcountmonth;  
        
          Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
          accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
          update accupdate;
      }else
      {
         KPIAccident__c kpi = new KPIAccident__c();
         List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
         kpi.Date__c=FBR.ModifyDate__c;        
          kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;        
         kpi.itemname__c= FBR.CommodityName__c;    
        
         Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
         kpi.MonthlyGeneratedCount__c=totalcountmonths;
         Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));
                   
         kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
         ToUpdate.add(kpi);
         insert ToUpdate;

}
}
} }

 

Above is my class, After save this go to Setup->Develop->Apex Classes then clicking on the ‘Schedule Apex’ button. and scheduled my class to run monthly but it doesn't get  start..

 

Is there any wrong what i did,, Please help me solve this

neophyteneophyte

You can check the status of your scheduled jobs in Administration setup -> Monitoring -> Scehduled Jobs. Please check if it is scheduled correctly.

 

Anand

ChermaduraiChermadurai

Hi Anand,

 

It Scheduled correctly.There is no status below in the column Started

 

Durai

neophyteneophyte

That means it has not run yet. Please check the scheduled run date. Your class will be executed only on that date.

 

-Anand

ChermaduraiChermadurai

Anand,

 

I Changed that specified date and time in my system..Still there is no changes..