-1

I wrote a trigger which attempts to grab the LastModifiedById and populate it to another field. When I use trigger.NewMap to get the LastModifiedById, it throws this error:

Error: Compile Error: Illegal assignment from Account to String

This is the line throwing the error:

String userIdString = trigger.newmap.get(acc.LastModifiedById);

Here's the complete trigger:

trigger Test on Account (after insert) 
{
    system.debug('test::'+trigger.new);
    for (account acc:trigger.new)
    {

        account dd = new account(id=acc.id);
        String userIdString = trigger.newmap.get(acc.LastModifiedById);

        dd.Last_Modified_By_End_User__c =userIdString.substring(0, 15);

        update dd;
    }
}

Why am I getting this error? How can I fix it?

1
  • 3
    What's the point of this? You don't need a trigger. Don't code if you don't need it. Just use a formula. Feb 13 '17 at 10:49
2

Change:

String userIdString = trigger.newmap.get(acc.LastModifiedById);

to:

String userIdString = trigger.newmap.get(acc.Id).LastModifiedById;

The description of error is quite obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.