以下のクラスは、logindate をカスタム フィールドにプッシュします。数式を使用して、日付/時刻から日付に変換できます。次に、apex を実行するようにスケジューラを設定して、最終ログイン日を最新の状態に保ちます。
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');
}