Aim – Pull the last login date from the user object into my custom object and populate a particular field
Now I am under the impression that LastLoginDate on the user object is not accessible through formulas in custom objects. The only way that LastLoginDate is accessible is through triggers
**Custom Object**
Object Name Mason_Object
API Name Mason_Object__c
**Field I would like to update is on the mason_object** Field Label : LastLogin Api Name : LastLogin__c Data type: Date/Time
I have written the following trigger (see below) however its not pulling through any values. Any ideas why ?
trigger lastloginDate on Mason_Object__c(before update) {
User u = [SELECT LastLoginDate FROM User WHERE Id =:UserInfo.getUserId()];
trigger.new[0].LastLogin__c = u.LastLoginDate;
}
after update
? A lot of system fields aren't set until the after transaction, seems strange, but might be worth looking into to – Ralph Callaway Jul 11 '14 at 0:16