You need to sign in to do that
Don't have an account?
t.deepthi05
task activity date
Hi,
I am updating my task activity date in lead using a trigger when ever i am creating a new task record on the lead object
but the activity date is wrongly updated in the lead
can i know why and here is my code
if(!leadIds.isEmpty())
{
leadsToUpdate = new list<Lead>([Select Id, Name, Activity_Date__c, (Select Id, ActivityDate From Tasks limit 100) From Lead Where Id in : leadIds limit 1]);
}
if(!leadsToUpdate.isEmpty()){
for(Lead l: leadsToUpdate)
{
for(Task t : l.Tasks)
{
if (t.ActivityDate > Date.today())
{
system.debug('t.ActivityDate'+t.ActivityDate);
l.Activity_Date__c = t.ActivityDate;
}
}
}
update leadsToUpdate;
}
I am updating my task activity date in lead using a trigger when ever i am creating a new task record on the lead object
but the activity date is wrongly updated in the lead
can i know why and here is my code
if(!leadIds.isEmpty())
{
leadsToUpdate = new list<Lead>([Select Id, Name, Activity_Date__c, (Select Id, ActivityDate From Tasks limit 100) From Lead Where Id in : leadIds limit 1]);
}
if(!leadsToUpdate.isEmpty()){
for(Lead l: leadsToUpdate)
{
for(Task t : l.Tasks)
{
if (t.ActivityDate > Date.today())
{
system.debug('t.ActivityDate'+t.ActivityDate);
l.Activity_Date__c = t.ActivityDate;
}
}
}
update leadsToUpdate;
}
Please try adding "l" to a different list and update that list, instead of the leadsToUpdate list. something like this:
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
This is a small trigger, see my code below.
Can you explain with details the issue you are facing? Like what date you are seeing and what date should be appearing?
Thanks,
Shashank
The udpate date in lead is 5/9/2014 5:00PM
I hope it is formating the date in a diffrent time zone and updating the lead
Unfortunately, we cannot change the system timezone preference from UTC to the user's timezone. The system will always run on UTC.
Depending on the timezone of the user, the user will see the date/time as per his timezone.
Also, one more important thing to note here is that the activitydate field on tasks is a date field, and not a date/time field. It does not hold the time. So, when it is assigned to a date/time field, the time will always be 00:00 UTC. This cannot be changed.
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
As a workaround, if your users are always in a timezone behind UTC, you can do a "activitydate+1", so that they will see your desired date. Something like:
l.Activity_Date__c = t.ActivityDate + 1 ;
l.Activity_Date__c = t.ActivityDate.addDays(1);
This will add a day but will not change the year.
The time will always be 00:00 GMT for activityDate field. To add your desired time to your lead activity date field, you can use the datetime instanec methods like addHours(), addMinutes(), addSeconds() etc. Please see this for more help: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm
something like
l.Activity_Date__c = t.ActivityDate.addDays(1);
l.Activity_Date__c = l.Activity_Date__c.addHours(7);