function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion


I'm trying to deploy this trigger:
trigger NaoFechaChamado on Case (after update) {
    Set <id> ids = new Set <id> ();
    for (Case c:{
        if (c.status=='Fechado'){
for (Case c: {
          for(Task t : [SELECT Id, WhatId,, subject FROM Task WHERE isclosed=false AND (Not subject like '%Fech%') AND whatid IN: ids]){
            if(c.status_do_processo__c != 'Extinto'){
            c.addError('Você não pode fechar um chamado com tarefas abertas. "'+t.subject+'" está aberta. Verificar com ''');
          for(Task t : [SELECT Id, WhatId,, subject FROM Task WHERE isclosed=false AND (subject like '%Fech%') AND whatid IN: ids]){
            if(c.status_do_processo__c != 'Extinto'){
            t.status = 'Concluído';
            update t;

I don't want to close my cases with tasks opened.
It works fine, but when I will deploy I get this error message "Failure Message: "System.DmlException: Update failed. First exception on row 0 with id 500U0000009hsErIAI; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Você não pode fechar um chamado com tarefas abertas. "Abertura de vaga - Aprovar vaga" está aberta. Verificar com CP7 Diretoria: []", Failure Stack Trace: "Class.Email_abertur..."

@isTest (seeAllData=true)
public class Email_abertura_de_vaga_test {

static testMethod void myUnitTest001() {
Case ca = new Case ();
    ca.Func_abertura_chamado__c = 'EVERTON GOMES';
    ca.motivo__c='Abertura de vaga';
    ca.Description='test test';
insert ca;

ca.resposta__c='teste'; ca.Func_abertura_chamado__c = 'ALAN BRONER';
    ca.motivo__c='Abertura de vaga'; ca.Nome_atendimento__c='Teste';
update ca;

I thought is because I have this another trigger:

trigger CriarTarefaCase_Abertura_de_vaga on Case (after insert) {

List<Task> tasks = new List<Task>();
    List<Case> cse =;
    for (Case c : cse){
            if (c.motivo__c == 'Abertura de vaga' && c.status != 'Fechado'){
          Task tsk = new Task
              (whatID = c.ID,
               Subject = 'Abertura de vaga - Aprovar vaga',
               ActivityDate =,
               Ownerid = '005U0000000FDE9');
insert tasks;

I found the problem, but I don't have any idea what I have to do to deploy my trigger "NaoFechaChamado".
Abhinav GuptaAbhinav Gupta
First of all a general warning, your triggers are not bulkified, you shouldnt do any DML or SOQL in loops. Please google and read about lots of good articles about bulkification practicies. If you dont take care of it now, it will bite you soon. 

It seems their is a validation rule in target org where you are deploying, and your record data is not complying with that. I would suggest examine the target org for validation rules, and fix your test data accordingly. Read more here on official salesforce help : (

It can't be a validation rule.
Because I deactivated all of them to see if this is the cause, but it doesn't.
The error that appears it is from my own trigger "NaoFechaChamado". Because SF understood in the test class "Email_abertura_de_vaga_test" that I'm inserting a case "Abertura de vaga" and the trigger "CriarTarefaCase_Abertura_de_vaga" is understanding when I create the case "Abertura de vaga" it will insert a task, when I try to update the case SF read the case "Abertura de vaga" with a task "Abertura de vaga - Aprovar vaga" and then appears my error.

I don't know what to do to made this test class understood that all the tasks are already closed.