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
SFD SalesforceSFD Salesforce 

can any one help me apex scheduler class

global class Monthly{
 
    public  static void ValAdd()//Set<Id> InquiryId
  {  
  
List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c  ];
{
Inquiry__c Fr= Inquiry[0];
Date startDate=fr.ModifyDate__c.toStartOfMonth();
Date endDate=fr.ModifyDate__c.toStartOfMonth().addMonths(1);
 
LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c where KPIInquiryContent__r.Account__c=:fr.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
 //LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:fr.KPIInquiryContent__r.Account__c];
 
List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where  Account_Name__c=:fr.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=fr.ModifyDate__c;         
          kpi.Account__c=fr.KPIInquiryContent__r.Account__c;         
         kpi.itemname__c= fr.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;
 
}
 }}
Pls help me apex scheduler class create  depending upon above code .
cheers
Pradeep
vishal@forcevishal@force

This isn't a schedulable class. Do you want to schedule this class? If yes, then you'll need to implement Schedulable Interface.

SFD SalesforceSFD Salesforce

Hi

ok.I created the scheduler class given below

 

my scheduler class is

 

global class MonthlySchedules21 implements Schedulable

{

global void execute(SchedulableContext ctx) {

ValAdd();
Datetime sysTime = System.now();
sysTime = sysTime.addSeconds(20);
String CRON_EXP= '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
system.debug(CRON_EXP);
FBR_InquiryMonthly1 f1=new FBR_InquiryMonthly1();
MonthlySchedules21 sch = new MonthlySchedules21();
system.schedule('Hourly Sync11', CRON_EXP, sch);
}

public void ValAdd()
{

List<Inquiry__c> Inquiry=[SELECT KPIInquiryContent__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__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]; //

for(FBR_Inquiry__c s : Inquiry)
{
KPIAccident__c accupdate = acc[0];
accupdate.MonthlyPPM__c= double.ValueOf(accupdate.MonthlyPPM__c);
}
update acc;
}
}

 

Action Job Name Submitted By Submitted Started Next Scheduled Run Type

 

 

Action Job Name Submitted By Submitted Started Next Scheduled Run Type
scheduledMonthly12
 9/20/2012 2:18 AM 10/1/2012 5:00 AMScheduled Apex

but it not working now. go to Monitoring-->scheduler jobs is not started the this class.pls help me and solution of this class..The above scheduler jobs shown in above.

cheers

Pradeep kumar.

SFD SalesforceSFD Salesforce

 

 

 

hi ,

This is for scheduler job.when ever the scheduler created in apex class. the class will be added in scheduler apex. it show

below screen.the started  link or button not shown the timing of adding schduler class.pls help me the below given solution

cheers

pradeep.

 

 

 

 

Action Job Name Submitted By Submitted Started Next Scheduled RunType