You need to sign in to do that
Don't have an account?

Works in Sandbox, fails in production
I have this trigger in sandbox and in production:
Trigger CriarTarefaCase_Solicitacao_Pagamento on Case (after insert, after update) { Set<String> setsubject=new Set<String>(); List<Task> lstNewTask=new List<Task>(); for(Task tsk:[SELECT Id, whatid, subject, status FROM Task WHERE (subject = 'Solicitação de Pagamento - Lançar PP' OR subject = 'Solicitação de Pagamento - Malote' OR (subject = 'Solicitação de Pagamento - Aprovar solicitação' AND status <> 'Concluído') OR subject = 'Solicitação de Pagamento - Não aprovada' OR subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal') AND whatid IN :Trigger.new]){ setsubject.add(tsk.subject); } for (Case c: trigger.new){ if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){ if ((c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0) && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){ if(!setsubject.contains('Solicitação de Pagamento - Lançar PP')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Lançar PP'; t.ActivityDate = Date.today(); lstNewTask.add(t); } } } if (c.status <> 'Fechado'){ if ((c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0) && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){ if(!setsubject.contains('Solicitação de Pagamento - Lançar PP')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Lançar PP'; t.ActivityDate = Date.today(); lstNewTask.add(t); } } } if (c.status <> 'Fechado'){ if ((c.forma_de_pagamento__c == 'MALOTE' || c.forma_de_pagamento__c == 'DEPÓSITO + MALOTE') && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){ if(!setsubject.contains('Solicitação de Pagamento - Malote')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Malote'; t.ActivityDate = Date.today(); t.Tarefa_de_fechamento__c = 'SIM'; t.Ownerid = '005U0000002KGXU'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){ if ((c.forma_de_pagamento__c == 'MALOTE' || c.forma_de_pagamento__c == 'DEPÓSITO + MALOTE') && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){ if(!setsubject.contains('Solicitação de Pagamento - Malote')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Malote'; t.ActivityDate = Date.today(); t.Tarefa_de_fechamento__c = 'SIM'; t.Ownerid = '005U0000002KGXU'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == null){ if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' && c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'MALOTE' && (c.Quantas_PP_s_pagamento__c < 1 || c.Quantidade_de_PP_s_Estojo__c < 1)){ if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){ Task t=new Task(); t.whatID = c.ID; t.Solicitar_Malote__c = true; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Aprovar solicitação'; t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA'; t.ActivityDate = Date.today(); t.Ownerid = '005U0000000FDE9'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == null){ if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' && (c.Quantas_PP_s_pagamento__c < 1 || c.Quantidade_de_PP_s_Estojo__c < 1)){ if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){ Task t=new Task(); t.whatID = c.ID; t.Solicitar_Malote__c = true; t.Solicitar_Dep_sito__c = true; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Aprovar solicitação'; t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA'; t.ActivityDate = Date.today(); t.Ownerid = '005U0000000FDE9'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == null){ if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c != 'MALOTE' && (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){ if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){ Task t=new Task(); t.whatID = c.ID; t.Solicitar_PP__c = true; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Aprovar solicitação'; t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA'; t.ActivityDate = Date.today(); t.Ownerid = '005U0000000FDE9'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == null){ if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'MALOTE' && c.outro_motivo__c != 'NÃO' && (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){ if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){ Task t=new Task(); t.whatID = c.ID; t.Solicitar_PP__c = true; t.Solicitar_Malote__c = true; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Aprovar solicitação'; t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA'; t.ActivityDate = Date.today(); t.Ownerid = '005U0000000FDE9'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == null){ if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' && (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){ if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){ Task t=new Task(); t.whatID = c.ID; t.Solicitar_PP__c = true; t.Solicitar_Malote__c = true; t.Solicitar_Dep_sito__c = true; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Aprovar solicitação'; t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA'; t.ActivityDate = Date.today(); t.Ownerid = '005U0000000FDE9'; lstNewTask.add(t); } } } if (c.status <> 'Fechado' && c.outro_motivo__c == 'NÃO'){ if(!setsubject.contains('Solicitação de Pagamento - Não aprovada')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Não aprovada'; t.ActivityDate = Date.today(); lstNewTask.add(t); } } if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){ if ((c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' || c.Nota_fiscal__c == 'SIM') && (c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados')){ if(!setsubject.contains('Solicitação de Pagamento - Solicitar Nota Fiscal')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal'; t.ActivityDate = Date.today(); lstNewTask.add(t); } } } if (c.status <> 'Fechado'){ if ((c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' || c.Nota_fiscal__c == 'SIM') && (c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados')){ if(!setsubject.contains('Solicitação de Pagamento - Solicitar Nota Fiscal')){ Task t=new Task(); t.whatID = c.ID; t.Solicita_o_de_Pagamento__c = c.motivo_a__c; t.Subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal'; t.ActivityDate = Date.today(); lstNewTask.add(t); } } } } insert lstNewTask; }
The first task works in production and in sandbox.
"Solicitação de Pagamento - Lançar PP"
But the second, doesn't work only in production.
"Solicitação de Pagamento - Malote"
Thanks!
Hi,
Please make sure that ids (t.Ownerid = '005U0000000FDE9') you are hardcoding are exists in Production.
If exist then let me know error statement so that I can provide a good solution.
Thanks
XXXForce
Yeah, I'am 100% sure that the ids exists.
No error appears to me, the task don't fired.
I put my own ID and in sandbox works perfect.
In production don't.
whether the mentioned user id(005U0000002KGXU) only creates task in ur production or the other users will create task.
u should not hardcode the value instead get the current logined user id by using this.userid = userinfo.getuserid();
and pass this to t.ownerid