You need to sign in to do that
Don't have an account?
Mark E 3
Update USER fields from TASK fields on TASK Create
I am spending too much time on this - and I thought this would be REALLY easy.
GOAL: Update USER custom fields with custom fields from TASK on TASK CREATE. Here's what I tried - it compiles, but does not work:
trigger UpdateLastChkInOnUser on Task (after insert) {
for(Task t: Trigger.new)
{
User u = [Select Id from User where Id = :t.whoId] ;
u.LastChkIn_DateTime__c = t.Check_In_Date_Time__c ;
u.LastChkIn_Latitude__c = t.Check_In_Latitude__c ;
u.LastChkIn_Longtitude__c = t.Check_In_Longtitude__c ;
update u;
}
}
GOAL: Update USER custom fields with custom fields from TASK on TASK CREATE. Here's what I tried - it compiles, but does not work:
trigger UpdateLastChkInOnUser on Task (after insert) {
for(Task t: Trigger.new)
{
User u = [Select Id from User where Id = :t.whoId] ;
u.LastChkIn_DateTime__c = t.Check_In_Date_Time__c ;
u.LastChkIn_Latitude__c = t.Check_In_Latitude__c ;
u.LastChkIn_Longtitude__c = t.Check_In_Longtitude__c ;
update u;
}
}
I think their is a gap in understanding ,in task who id can be contact or lead , so it can't be user so trigger you have written wont work .
t.whoId will be contactid or lead id
please like if its help
All Answers
I think their is a gap in understanding ,in task who id can be contact or lead , so it can't be user so trigger you have written wont work .
t.whoId will be contactid or lead id
please like if its help
But code written above is not up to best practices as it is not bulkify . so make changes . Thanks
please like if its help
trigger UpdateLastChkInOnUser on Task (after insert) {
List<User> userList = new List<User>();
for(Task t: Trigger.new)
{
User u = new User();
u.Id = t.OwnerId;
u.LastChkIn_DateTime__c = t.Check_In_Date_Time__c;
u.LastChkIn_Latitude__c = t.Check_In_Latitude__c;
u.LastChkIn_Longtitude__c = t.Check_In_Longtitude__c;
userList.add(u);
}
update userList;
}