I have a trigger where I'm trying to make it work like the following: When a Activity record is inserted by a user that matches the value in a user lookup field on Accounts named "Customer Success Manager", the created date of the activity goes in the CE_Last_Activity__c field on Accounts. I keep getting the following error: Error: Compile Error: line 21:13 no viable alternative at character '$' at line 21 column 13". The line starts with if(!$User.Name
Here is what I have so far:
trigger CELastActivity on Task (after insert) {
datetime myDate = datetime.now();
List<Account> accToUpdate = [SELECT Id,CE_Last_Activity__c FROM Account WHERE Customer_Success_Manager__c != Null];
Map<Id, Task> taskMap = new Map<Id, Task>();
for (Task t: Trigger.New){
if (t.WhatId != null ){
taskMap.put(t.WhatId, t);
}
}
system.debug('taskMap = '+taskMap);
if (taskMap.size() > 0)
{
accToUpdate = [SELECT Id, CE_Last_Activity__c
FROM Account
WHERE Id IN: taskMap.keySet()];
for (Account a: accToUpdate){
if (!$User.Name = a.Customer_Success_Manager){
a.CE_Last_Activity__c = myDate;
}
system.debug('accToUpdate = '+accToUpdate);
if (accToUpdate.size() > 0)
{
update accToUpdate;
}
}
}