You need to sign in to do that
Don't have an account?
Marty Dorren
Code in Anonymous works but....
Hi,
I'll apologize ahead of time...
I have some class code that inserts records to a custom object and works fine in anonymouse as long as I comment out the class and method lines at the top. I have to put this class in a schedule and the schedule runs but the class does NOT execute. I fear I'm missing something very basic, but at this point, I'm in quicksand. Here's the code... very simple:
public class Daily_SD_Insert_SVIRA {
public static void DoSDInsert() {
date tdy = system.date.today();
date SvcDate = system.date.today();
date FirstofLast = date.valueOf(system.date.newInstance(system.today().year(),system.today().month()-1,01));
date LastofLast = FirstofLast.addMonths(1).toStartofMonth().addDays(-1);
string IPRecType = '012Z00000004nSCIAY';
string SDRecType = '012Z00000004nS7IAI';
string MSRecType = '012F0000000muqTIAQ';
//SD Inserts
//Create SD Lists
List<Individual_Programs__c> IPRGSD1 = [select Id, service__c from individual_programs__c where (
(Status__c = 'Enrolled' and enroll_date__c < today )
and RecordTypeId = :IPRecType and
Id NOT IN (Select Individual_Program__c from service_documentation__c where
service_date__c = :SvcDate and RecordTypeID = :SDRecType))];
system.debug('IPRGSD1 = '+IPRGSD1);
List<service_documentation__c> sda = new List<service_documentation__c>();
//Insert SD
INTEGER ipcnt = 0;
for (Individual_Programs__c IPRGSD : IPRGSD1) {
sda.add (new service_documentation__c(
service_Date__c = SvcDate,
Billable_hours__c = 0,
Billable_minutes__c = 0,
RecordTypeId = SDRecType,
service__c = IPRGSD.service__c,
Individual_Program__c = IPRGSD.Id));
system.debug('IPRGSD-Individual_Program__c = '+IPRGSD.Id+ ' |count:'+ipcnt);
ipcnt = ipcnt+1;
}
Database.insert(sda);
}
}
Thanks ahead of time...
Marty
I'll apologize ahead of time...
I have some class code that inserts records to a custom object and works fine in anonymouse as long as I comment out the class and method lines at the top. I have to put this class in a schedule and the schedule runs but the class does NOT execute. I fear I'm missing something very basic, but at this point, I'm in quicksand. Here's the code... very simple:
public class Daily_SD_Insert_SVIRA {
public static void DoSDInsert() {
date tdy = system.date.today();
date SvcDate = system.date.today();
date FirstofLast = date.valueOf(system.date.newInstance(system.today().year(),system.today().month()-1,01));
date LastofLast = FirstofLast.addMonths(1).toStartofMonth().addDays(-1);
string IPRecType = '012Z00000004nSCIAY';
string SDRecType = '012Z00000004nS7IAI';
string MSRecType = '012F0000000muqTIAQ';
//SD Inserts
//Create SD Lists
List<Individual_Programs__c> IPRGSD1 = [select Id, service__c from individual_programs__c where (
(Status__c = 'Enrolled' and enroll_date__c < today )
and RecordTypeId = :IPRecType and
Id NOT IN (Select Individual_Program__c from service_documentation__c where
service_date__c = :SvcDate and RecordTypeID = :SDRecType))];
system.debug('IPRGSD1 = '+IPRGSD1);
List<service_documentation__c> sda = new List<service_documentation__c>();
//Insert SD
INTEGER ipcnt = 0;
for (Individual_Programs__c IPRGSD : IPRGSD1) {
sda.add (new service_documentation__c(
service_Date__c = SvcDate,
Billable_hours__c = 0,
Billable_minutes__c = 0,
RecordTypeId = SDRecType,
service__c = IPRGSD.service__c,
Individual_Program__c = IPRGSD.Id));
system.debug('IPRGSD-Individual_Program__c = '+IPRGSD.Id+ ' |count:'+ipcnt);
ipcnt = ipcnt+1;
}
Database.insert(sda);
}
}
Thanks ahead of time...
Marty
I don't see any schedulable interface in your Class.So,you won't be able to schedule it.That's why I was asking how you are doing that.I thought you are calling this class from some other schedulable interface class.
So,your class structure should be something like below :-
If this helps,please mark it as best answer to help others :)
All Answers
I don't see any schedulable interface in your Class.So,you won't be able to schedule it.That's why I was asking how you are doing that.I thought you are calling this class from some other schedulable interface class.
So,your class structure should be something like below :-
If this helps,please mark it as best answer to help others :)
global class Daily_SD_Insert_SVIRA_Sched implements Schedulable {
global void execute(SchedulableContext SC) {
Daily_SD_Insert_SVIRA myPageCon = new Daily_SD_Insert_SVIRA();
myPageCon.DoSDInsert();
}
}
I'm still not sure why I had to do that but of course, I'm happy that it did.
Many thanks.
Marty
The class which I was calling has everything(all operations) in constructor,so I have to just intialize it and I am good to go.For you,you have to call the method to as you were doing operation inside the method.
Hope this clears your doubt..