+ Start a Discussion
EvertonSzekeresEvertonSzekeres 

Task OwnerID

Hi !

 

I'm trying to set the ownerid from a specific taks.

 

trigger CriarTarefa_Impressao_e_Nova_separacao2 on Task (after update) {
    
    
Set<Id> ownerId=new Set<Id>();
    List<Task> taskNova = new List<Task>();   

     for(Task tsk:[SELECT Id, ownerid, whatid FROM Task WHERE subject = '- Iniciador do Fluxo -' AND id IN :Trigger.new])
        ownerId.add(tsk.ownerid);
 
    for (Task t : Trigger.new){
        Task oldt = Trigger.oldMap.get(t.ID);
    
        if(t.status != oldt.status){
            
        if (t.subject == 'Impressão - Atualização de dados' && t.status == 'Concluído'){
                taskNova.add (new Task(
                         Subject = 'Impressão - Formando tem fotos separadas?',
                         Status = 'Nenhum',
                         WhatID = t.WhatID,
                         Description = t.description,
                         OwnerId = ownerid,
                         ActivityDate = Date.today()));
    }
            if (t.subject == 'Impressão - Formando tem fotos separadas?' && t.Formando_tem_montagens__c == 'SIM' && t.status == 'Concluído' || t.subject == 'Impressão - Preencher quantidades' && t.Formando_tem_montagens__c == 'SIM' && t.status == 'Concluído'){
                taskNova.add (new Task(
                         Subject = 'Impressão - Informe o caminho da pasta',
                         Status = 'Nenhum',
                         WhatID = t.WhatID,
                         Description = t.description,
                         OwnerId = ownerid,
                         ActivityDate = Date.today()));
       }
    }
    insert taskNova;
            }

 

But I get this error:

"Invalid initial expression type for field Task.OwnerID, expecting: Id"

Avidev9Avidev9
Well it seems like you never declared "createdbyId".
What are you planning to do ?
Change the task Owner TO created User ?

I guess then you have to do something like
OwnerID = t.CreatedById;
mbhardwajmbhardwaj
Try to chnge this line to

OwnerId = ownerid,

to

OwnerId = t.ownerid,

if that's what you need.
EvertonSzekeresEvertonSzekeres

Actually I tried to set the owner of "- Iniciador do fluxo -" and put in my other tasks.

 

I create another trigger to update this owner and works here.

 

Thanks for help !