+ Start a Discussion
Veerendar AellaVeerendar Aella 

i want to automate last login users greater than 30 days , an email as to be sent to managers with the same.

Hi All, 
When a last login user is greater than 30 days, then I want to send a automated email to the respective managers.
This can done by using
workflow
Process Builder
apex class
Please advice
Raj VakatiRaj Vakati
You have to apex scheduler jobs 

Use this sample code and implement email logic
 
global class LastLoginEmailJObs implements Schedulable {
   global void execute(SchedulableContext SC) {
    List<User> uds =[SELECT LastLoginDate FROM User]
	for(User u : uds){
	If( u.LastLoginDate<=System.today().addDays(-30)){
	// EMail Logic will go here 
	}
	}
   }
}


 
RbnRbn
Hi veerendar,

you can make use of workflow rule and time depen workflow rule to trigger an email alert to the manager.

Create a workflow rule on user object with some criteria like : If user is Active - True, then add a time dependent workflow action.

Please refer the below screenshot.

User-added image

Let me know if this helps.

Regards,
Rabindranath
Mallik1221Mallik1221
Hi Raj,
Here is my requirement, could you please help me with this as Im new to development.

Schedulable Apex class to send an email to users whose last login is more than 30 days. what will be the email logic.

Regards
Malli
Raj VakatiRaj Vakati
You have to use Single Email Message or mass email message logics 
 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
List <Contact> Con= [select id, name from Contact where name =:'xx']; 
mail.setTargetObjectId(Con[0].id); 
mail.setSenderDisplayName('Salesforce Support'); 
mail.setUseSignature(false); 
mail.setBccSender(false); 
mail.setSaveAsActivity(false); 
EmailTemplate et=[Select id from EmailTemplate where Name=:'SFDC TEST']; 
mail.setTemplateId(et.id); 
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });