You need to sign in to do that
Don't have an account?
developer_force
Update a task field
Hi,
Help needed in updating a custom field on Task
I have a custom field calld Sales_Targer_Id__c on task object and this field need to be get updated by the Id of Sales_Target__c object
And the condition for that is if the officer_code__c of Task is equal to Officer_code__c of sales_Target__c object then update the Sales_Targer_Id__c custom field with the id of the Sales_Target__c custom object.
Thanks
Assuming that the task is a child of the Sales_Target__c object (task.WhatId = Sales_Target__c) I'd write a trigger that like this:
I've not compiled or tested the trigger, so it might need some polishing
Thank you for your response.
But This an after insert trigger on Sales_Target__c object.
And there is no relation between Task and Sales_Target__c object. Task object just has a Custom field 'Sales_Target__c' which is of data type Text(18)
This custom field on task should get updated with the Sales_Target__c object's id.
Thanks
So, after a Sales_Target__c record has been inserted you want to create a new task with the ID from the newly created Sales_Target__c in the Task.Sales_Target_Id__c field?
After the Sales_Target__c records are inserted , the custom field 'Sales_Target_ID__c' on Task should get updated with the id of Sales_Target__c object based on the following condition
if(
task.Officer_code__c = Sales_Target__c.Officer_code__c and
task.Activitydate <= Sales_Target__c.Target_Period_End__c and
task.Activitydate <= Sales_Target__c.Target_Period_Start__c ) this si condition is met then update the custom field on task
Hope its clear now. Its kind of urgent pls
Thanks
This is closer then... The challenge in your requirement is that each Sales_Target__c has its own start and end date, and querying one by one for the appropriate task is going to hit the Governor limits.
So the trigger finds the earliest start date, and the latest end date and finds all tasks that occur within that range where the Officer code is in the Sales_Target__c set being processed.
It then tests each of the tasks to ensure that the task occurs within the time frame of the appropriate Sales_Target__c.
Thank You so much for the quick response but iam getting the error as
Illegal assignment from Id to SOBJECT:Sales_Target__c at line 15 column 1 in the below line
Sales_Target__c st = offCode2stId.get(t.Officer_Code__c);
Thanks
HI fgwarb,
Thanks for the reply
Iam the same one holding two usernames , developer_force and this.
I tried with yor code but still the Sales_Target__c lookup field on Sales_Opportunity__c object is not getting updated with the id of the Sales_target__c object.
pls let me know what can be done. Its urgent pls
Thanks
Hello Again!
We've been discussing Task & Sales_Target__c objects. How does Sales_Opportunity__c fit into your requirement?
Yep sorry,
There is also the same scenario as task with the Sales_opportunity__c as well
Sorry again. Lets work with the Task first then i can do the same thing with the sales_Opportunity__c as well.
Task[] tasksToUpdate = new Task[]{};
for(Task t : [SELECT Id, ActivityDate
FROM Task
WHERE ActivityDate <= :targetEnd
AND ActivityDate >= :targetBeg
AND Officer_Code__c IN :offCode.keySet()]){
Sales_Target__c st = offCode.get(t.Officer_Code__c);
if(st.Officer_Code__c!=null){
if(t.ActivityDate <= st.Target_Period_End__c && t.ActivityDate >= st.Target_Period_Start__c){
t.Sales_Target_Id__c = st.Id;
tasksToUpdate.add(t);
}
}
}
With the above code , thes Sales_Target_ID__c text field is not getting updated with the id of Sales_target__c
Thanks