+ Start a Discussion
Sainath VenkatSainath Venkat 

Trigger not updating last login from user to account object

I created one trigger on User object which will update the last login to account if account name matches with user.Name field.

but somehow my trigger is not at all updating the lastlogin field on account object even though name matches, can anyone helps me out in this issue here.

My trigger code is below
trigger USERLOGIN on User (after insert, after Update) {
    map<string, User> ObjMap = new map<string, User>();
    for(User obj: Trigger.new)
        if (obj.Name != Null)
            ObjMap.put(obj.Name, obj);
    system.debug('UserMap :' + ObjMap);
    List<Account> accounts = [SELECT Id, logindate__c,Name FROM Account WHERE Name IN :ObjMap.KeySet()];
    List<Account> accUpdateList = new List<Account>();
    system.debug('Account :' + accounts);
    for(Account c: accounts)
        User obj = ObjMap.get(c.Name);
        c.logindate__c = obj.LastLoginDate;
        c.usertextemail__c = obj.Email;
    if(accUpdateList.size() > 0)
        update accUpdateList;

Ravi Dutt SharmaRavi Dutt Sharma
Hi Sainath,

Is this trigger even compiling? I am not able to see a field named "LastLoginDate" on the User object.
Sainath VenkatSainath Venkat
yes its compiling, I checked debug logs too but I dont know field update is not happening at all.

its not visible but we can do query on that field