I would like to apologise if any spelling mistakes , in currently posting this on an iPhone whilst I commute home
I found a link online which I think meets my requirements
As we are all aware lastlogin date on user object is accessible via formulas and triggers. However I been told it can be accessed via visual force pages and a batch apex. I don't want to go down the route of visual force so in looking at batch apex.
I want to get the last login date from the user object an populate anther field in a custom object. The field I would like to populate is abc_test, and object is called mason
I have found the following trigger but I don't no why field names I need to change to meet my critters, and whether this trigger should be put in my custom object or user object
I am aware that this needs to be scheduled job aswell
Looking forward to your help D
public void ResetlastLogin_Update(List<User> oldUsers, List<User> newUsers) {
System.debug('ResetlastLogin_Update: entering trigger');
List<Id> idsToUpdate = new List<Id>();
for (integer i=0; i<newUsers.size(); i++) {
User newVals = newUsers[i];
User oldVals = oldUsers[i];
if (newVals.lastlogindate != oldVals.lastlogindate__c) {
idsToUpdate.add(newVals.Id);
}
}
System.debug('Ids to Update: ' + idsToUpdate.size());
if (idsToUpdate.size() > 0) {
List<User> usersToUpdate = [SELECT Id, lastlogindate, lastlogindate__c FROM User WHERE Id IN :idsToUpdate];
for (User u : usersToUpdate) {
if (u.lastlogindate__c == NULL ) {
u.lastlogindate__c = u.lastlogindate ;
}
}
update usersToUpdate;
}
System.debug('ResetlastLogin_Update_Update: exiting trigger');
}