You need to sign in to do that
Don't have an account?
Beth Strella
I want to create a field that has the last time the account was touched that was not done by a system admin.
I want to create a field that has the last time the account was touched that was not done by a system admin.
By touch, I mean Newest date out of the following: Task Created date, Event created to date, task modified date, event modified date.
This trigger was built for us but doesn’t exclude the System admin as well as doesn’t give us the last day if they created an activity just gives us a modified date. Not really sure how to fix it/ adjust it. Any help is appreciated. I have never used Apex before.
trigger UpdateLastActivityDate4318 on Task (after insert, after update, after delete, after undelete)
{
Set<Id> accountIds = new Set<id>();
if(Trigger.isDelete)
{
//always get the old for deleted activities
for(Task t : Trigger.old)
{
accountIds.add(t.AccountId);
}
}
else
{
for(Task t : Trigger.new)
{
accountIds.add(t.AccountId);
}
}
List<Account> accounts =
[
SELECT
Id,
(
SELECT
Subject,
LastModifiedDate
FROM Tasks
ORDER BY isClosed ASC, LastModifiedDate DESC
LIMIT 1
),
Last_Activity_Date__c
FROM Account
WHERE Id in :accountIds
];
for (Account a : accounts)
{
system.debug(a);
if(a.Tasks.size() > 0)
{
system.debug(a.Tasks[0]);
a.Last_Activity_Date__c = a.Tasks[0].LastModifiedDate;
}
else
{
a.Last_Activity_Date__c = null;
}
}
update accounts;
}
}
By touch, I mean Newest date out of the following: Task Created date, Event created to date, task modified date, event modified date.
This trigger was built for us but doesn’t exclude the System admin as well as doesn’t give us the last day if they created an activity just gives us a modified date. Not really sure how to fix it/ adjust it. Any help is appreciated. I have never used Apex before.
trigger UpdateLastActivityDate4318 on Task (after insert, after update, after delete, after undelete)
{
Set<Id> accountIds = new Set<id>();
if(Trigger.isDelete)
{
//always get the old for deleted activities
for(Task t : Trigger.old)
{
accountIds.add(t.AccountId);
}
}
else
{
for(Task t : Trigger.new)
{
accountIds.add(t.AccountId);
}
}
List<Account> accounts =
[
SELECT
Id,
(
SELECT
Subject,
LastModifiedDate
FROM Tasks
ORDER BY isClosed ASC, LastModifiedDate DESC
LIMIT 1
),
Last_Activity_Date__c
FROM Account
WHERE Id in :accountIds
];
for (Account a : accounts)
{
system.debug(a);
if(a.Tasks.size() > 0)
{
system.debug(a.Tasks[0]);
a.Last_Activity_Date__c = a.Tasks[0].LastModifiedDate;
}
else
{
a.Last_Activity_Date__c = null;
}
}
update accounts;
}
}
First on account you have to create new formula field :
Formula field which give you last modified profile name ::::: LastModifiedBy.Profile.Name (Which give you last modified user profile name )
after you will create new formula field name :::Last modified date
formula is ::
IF(Last_Prodile_Name__c <> 'System Administrator',
DATEVALUE(LastModifiedDate ) ,
null )
Let me know if you need anyhelp or mark this answer as a best answer!!!
but shoudl return 4/4/2018 since Dan Nikolich created an activity today
condition to update that date field is ::: Last_Prodile_Name__c <> 'System Administrator' it will update with last modified date DATEVALUE(LastModifiedDate )
if it Last_Prodile_Name__c == 'System Administrator' then put PRIORVALUE( New Field ) )
IF(LastModifiedBy.Profile.Name <> 'System Administrator',
DATEVALUE(LastModifiedDate ) ,
PRIORVALUE(LastModifiedDate))
I get this error Error: Function PRIORVALUE may not be used in this type of formula
I have used a prior value before in an if statement so not sure why it doesn't allow it this time.