notify user by sending an email to user whose last-login is more than 1 day

Here is my code, please check global class LastLoginEmail implements Schedulable { global void execute(SchedulableContext SC) { List<User> uds =[SELECT Id, LastLoginDate, Email FROM User where IsActive=True]; EmailTemplate et=[Select id from EmailTemplate where Name=:’Users_Please_login’]; Messaging.SingleEmailMessage[] mails = new Messaging.SingleEmailMessage[0]; for(User u : uds){ If( u.LastLoginDate<=System.today().addDays(-1)){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId(‘User ID’); mail.setSenderDisplayName(‘Salesforce Support’); mail.setUseSignature(false); … Read more

Test classes for Scheduled Apex classes [duplicate]

This question already has an answer here: How do I increase my code coverage, or why can’t I cover these lines? (1 answer) Closed 3 years ago. Below I have shared the APEX code and the Test class code. I receive 100% code coverage, but I cannot grasp certain parts of it. Eg. The system.assert … Read more

Who is the sender for a SimpleEmailMessage sent inside an scheduled apex class?

If I have a scheduled job that periodically runs and queries a custom object, then creates a simpleEmailMessage and uses Messaging.sendEmail(), who will the sender for that email be? The user who scheduled it? Thanks! Answer Yes, the user who schedules the class will be the sender of the email. This is true for all … Read more

Create a task if a particular if a date lapses? Scheduled APEX the only option?

I feel like I may be missing something obvious here, but I have a certain field that is populated with a future date. I would like to ensure that follow-up tasks are created when that due date lapses, i.e. it is not updated to a date further in the future. Note that there is no … Read more

Scheduling Flow

I am trying to create a screen flow that is scheduled in Salesforce. From the screen flow I call an Invocable method where I pass my input parameters from my screen flow. From there I call a future method which passes on these values and then finally make my POST callout. My only issue is … Read more

How to unit test the method that schedules an apex schedulable class

I have a method that executes the following code , I am not able to find any thing from CronTrigger to verify the scheduled job public static void ScheduleStatusChk(Id batchId, Set<Id> addressIds, Id accountId, Id documentId){ CheckBulkStatus chkStatus = new CheckBulkStatus(batchId,addressIds ,accountId,documentId); Datetime dt = Datetime.now().addSeconds(30); String timeForScheduler = dt.format(‘s m H d M \’?\’ … Read more

calling two separate methods in an schedulable class based on time interval

I have One schedulable class that calls a method that have multiple if conditions to be executed FOR(Contact cont : contacts){ if(cont.Account.Due_date_of_last_open_invoice__c == system.today() + 14) { template = DueInvoice; } if(cont.Account.Due_date_of_last_open_invoice__c == system.today()) { template = DueInvoice; } if(cont.Account.Due_date_of_last_open_invoice__c == system.today() + 7){ template = DueInvoice; } if(cont.Account.Due_date_of_last_open_invoice__c == system.today() – 7){ template = … Read more

Code efficiency when using same content in multiple method in same class

what I should learn and do if I have 3 different methods that are essentially doing the same thing but only the query statement that makes the differences. For instance my code below have 2 methods and do some SOQL,DML and Email send out, essentially both are doing exactly the same which is sending an … Read more