You need to sign in to do that
Don't have an account?
Everton CP7
Get OwnerID from task
I'm trying to get the same ownerID from task "test 1" to task "test 3" when I complete the task "test 2".
trigger CriarTarefa_Impressao_e_Nova_separacao on Task (before update) { List<Id> ownerIds = new List<Id>(); for (Task task : Trigger.new) { if (task.subject == 'test 1') { ownerIds.add(task.ownerId); } } List<Task> owners = [SELECT Id, ownerId FROM Task WHERE ownerId IN :ownerIds]; Map<Id,String> ownerIdsTo = new Map<Id,String>(); for (Task owner : owners) { ownerIdsTo.put(owner.Id,owner.ownerID); } List<Task> taskNova = new List<Task>(); for (Task task : Trigger.new) if (task.subject == 'test 2' && task.status == 'Completed'){ taskNova.add (new Task( Subject = 'test 3', Status = 'Nenhum', WhatID = task.WhatID, Description = task.description, Ownerid = ownerIdsTo.get(task.OwnerId), ActivityDate = Date.today())); }
With this code the OwnerID returns null.
Hi
What you are trying to get createdby or AssignedTo?
If its createdby then in soql query use Createdbyid instead of ownerid.
just look at this link also:-http://blogs.developerforce.com/developer-relations/2011/03/a-neat-soql-trick.html
It is possible to be createdby or AssignedTo.
I changed.
But still giving me the same error.
Question: Do you update all 3 Tasks with one bulk update or just Test 2 ?
If you only update Test 2 then your ownerIds list will be empty, your SoQL will return empty list and thus Map is empty...
Try this.
I had to create another account here.
I changed some things in my configuration.
I tried put this ID firstTaksOwnerId;
And the same happens.
I will get a better explanation.
"Test" 1 is one task that is been created by workflow.
From this task my trigger begins.
I have much more tasks in this same trigger, but its just copy and paste.
If Task1 is Created then it's not in your Trigger context... Your trigger fires only Before Update
Am I missing something ?
This will works if I pull the creator's case too.
Task "test 1" its always from a case.
I already tried this and didn't work. Probably I did something wrong.
Some help?
That's right, "Test 1" it's not in my trigger context.
But this works if I put user ID in there.
Why didn't work if I try put ownerID from "test 1"?
Can you put a debug statement there to see what Owner Id you are getting in trigger from first task?
Because probably the User.Id somehow exists in the Map and thus you get a result from the get operation ;-)
FINALLY I DID !!!
Thanks all of you guys !
For attention and help !