You need to sign in to do that
Don't have an account?
SFD 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
This isn't a schedulable class. Do you want to schedule this class? If yes, then you'll need to implement Schedulable Interface.
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;
}
}
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.
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.