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

Code coverage is in 74%
Hi,
I created this trigger:
trigger CriarTarefa_Produtos_Cobranca on Task (after update) { List<Task> taskProd = new List<Task>(); for (Task tt : Trigger.new) if (tt.subject == 'Cobrança - Problemas com produtos' && tt.status == 'Concluído' || tt.subject == 'Cobrança - Pergunta não solucionada' && tt.status == 'Concluído'){ taskProd.add (new Task( Subject = 'Cobrança - Questão solucionada?', Status = 'Nenhum', WhatID = tt.WhatID, Description = tt.description, OwnerId = '005U0000001KrXY', ActivityDate = Date.today())); } for (Task tt : Trigger.new) if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'SIM' && tt.status == 'Concluído'){ taskProd.add (new Task( Subject = 'Cobrança - Feche o chamado e notifique o formando', Status = 'Nenhum', WhatID = tt.WhatID, Description = tt.description, OwnerId = '005U0000001KrXY', ActivityDate = Date.today())); } for (Task tt : Trigger.new) if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'NÃO' && tt.status == 'Concluído'){ taskProd.add (new Task( Subject = 'Cobrança - Pergunta não solucionada', Status = 'Nenhum', WhatID = tt.WhatID, Description = tt.description, OwnerId = '005U0000000FrCz', ActivityDate = Date.today())); } insert taskProd; }
And my test class:
@IsTest(SeeAllData=true) public class CriarTarefa_Pendencia_Duomind_test{ static testmethod void MyUnitTest(){ User u = [select id from User where LastName='Marketing']; Case c = new Case (recordtypeid='012U000000011yC'); Task tsk = new Task(Status='Não iniciado', Priority='Normal', subject='- Iniciador do Fluxo -'); insert tsk; tsk.Status = 'Concluído'; update tsk; } }
My code coverage is in 74%.
What I'm missing here?
Any help?
Thanks !
All Answers
But my problem is that I can't import to my org.
I'm still in Sandbox.
Thanks !
Yeah. That's right !
Why are there 3 "for" loops? Shouldn't your "if" statements just be inside one "for" loop? Maybe I am reading it wrong but you're also missing curly brackets on the "for" loops.
You're right InsightTeam!
I fix that.
Thanks !
Still trying to find where I'm get this 74% of code coverage.
I think that I almost there.
I think part of the reason is your test does not set the subject and other fields to the values you are checking for in your "if" statements. I'm still somewhat new to apex but below is an example of how I would have written your class. All you'd need to do is add in lines of code to your test so that it will cover the conditions in each of your "if" statements. I think you can even go as far as to use a list to insert the tasks so that you don't run the risk of pushing the limits.
Add 1 task for each of your if clauses in the code, presently you are inserting 1 task:
Task tsk = new Task(Status='Não iniciado', Priority='Normal', subject='- Iniciador do Fluxo -');
Add more tasks in test class:
Task tsk2 = new Task(.....);
Task tsk3 = new Task(...);
That will make your test class cover the conditions in your code and improve coverage.
I think this will work !
But I'm getting one error when I try to save the class.
Error: Compilation error: Expression cannot be assigned na linha -1 column -1
Thanks !
I founded one class that have 0% of coverage.
I modify that class and now my trigger works !
You're right since the beggining Tech Force!
Thanks !