We can call it but not recommended to use Scheduler/batches(10 Scheduled Jobs at a given time) in the triggers because they might trigger for any modification on the record.
global class scheduledMonthly implements Schedulable {
/**
* Builds up all of the new Objects
*
* @param sc The schedulable context
*/
global void execute(SchedulableContext sc) {
RecordType rt = [
select Id
from RecordType
where DeveloperName = 'Recipient'
];
List<MyObject__c> objectList = new List<MyObject__c>();
//Get all of the accounts of type 'Recipient'
for (Account account: [
select Id
from Account
where RecordTypeId = :rt.Id
]) {
objectList.add(new MyObject__c(
Account__c = account.Id
));
}
if (!objectList.isEmpty()) {
insert objectList;
}
}
}
We can call it but not recommended to use Scheduler/batches(10 Scheduled Jobs at a given time) in the triggers because they might trigger for any modification on the record.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
Please mark as best answer if it helps you:)
Thanks,
Jay
In addition to what Jayanth has mentioned please refer to this link
https://developer.salesforce.com/forums/?id=906F00000008zgyIAA
Regards
Pankaj Shakya