• Guilherme Tavares
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I'm trying to test a trigger that updates the Case Status field, but the assert is failing on Test Class, can anyone help me with this? 

Here is the Test Class
@isTest 
private class AtualizaStatusDoChamadoTest {
    
    private static testmethod void testaTrigger(){
        Case novoCaso = new Case();
        novoCaso.Nome__c = 'Teste';
        novoCaso.Status = 'Em aberto';
        novoCaso.Email__c = 'teste@teste.com';
        insert novoCaso;

        Comentario_caso__c novoComentario = new Comentario_caso__c();
        novoComentario.Caso__c = novoCaso.Id;
        novoComentario.Tipo_de_Comentario__c = 'Encerramento';
        insert novoComentario;   
        
        Case caso = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
        
        Test.startTest();
        System.assertEquals('Encerrado', caso.Status);
        Test.stopTest();
    }
}

Here is the Trigger
trigger AtualizaStatusDoChamado on Comentario_Caso__c (before insert, before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            List<Comentario_Caso__c> listaDeComentarios = trigger.new;
            Comentario_Caso__c novoComentario = listaDeComentarios[0];
            Case casoDoComentario = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
            if(novoComentario.Tipo_de_Comentario__c == 'Encerramento'){
                casoDoComentario.Status = 'Encerrado';
            }    
            System.debug('caso: ' + casoDoComentario);
        }
    }
}

Log
11:52:42:863 EXCEPTION_THROWN [19]|System.AssertException: Assertion Failed: Expected: Encerrado, Actual: Em aberto

On the Trigger, the debug is showing the correct Status, maybe I'm doing something wrong when trying to get the updated Case on Test Class.
I'm trying to test a trigger that updates the Case Status field, but the assert is failing on Test Class, can anyone help me with this? 

Here is the Test Class
@isTest 
private class AtualizaStatusDoChamadoTest {
    
    private static testmethod void testaTrigger(){
        Case novoCaso = new Case();
        novoCaso.Nome__c = 'Teste';
        novoCaso.Status = 'Em aberto';
        novoCaso.Email__c = 'teste@teste.com';
        insert novoCaso;

        Comentario_caso__c novoComentario = new Comentario_caso__c();
        novoComentario.Caso__c = novoCaso.Id;
        novoComentario.Tipo_de_Comentario__c = 'Encerramento';
        insert novoComentario;   
        
        Case caso = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
        
        Test.startTest();
        System.assertEquals('Encerrado', caso.Status);
        Test.stopTest();
    }
}

Here is the Trigger
trigger AtualizaStatusDoChamado on Comentario_Caso__c (before insert, before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            List<Comentario_Caso__c> listaDeComentarios = trigger.new;
            Comentario_Caso__c novoComentario = listaDeComentarios[0];
            Case casoDoComentario = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
            if(novoComentario.Tipo_de_Comentario__c == 'Encerramento'){
                casoDoComentario.Status = 'Encerrado';
            }    
            System.debug('caso: ' + casoDoComentario);
        }
    }
}

Log
11:52:42:863 EXCEPTION_THROWN [19]|System.AssertException: Assertion Failed: Expected: Encerrado, Actual: Em aberto

On the Trigger, the debug is showing the correct Status, maybe I'm doing something wrong when trying to get the updated Case on Test Class.

i want to update the account filed Desc when any new account is created or update with the desc filed contain 12345

here is my code it not allowing me to create record!!!!!

Not allowing to crete record showing error

//updateDesc: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.updateDesc: line 11, column 1

Thanks is advance 

 


trigger updateDesc on Account (after insert,after update) {
  List<Account> accList = new List<Account>();
    
    for(Account acc : Trigger.new)
        if(acc.Description =='12345')
    {
        Account accountobj = new Account();
        accountobj.Description=' Test trigegr';
        accList.add(accountobj);
    }
    update accList;
}

 

I'm trying to test a trigger that updates the Case Status field, but the assert is failing on Test Class, can anyone help me with this? 

Here is the Test Class
@isTest 
private class AtualizaStatusDoChamadoTest {
    
    private static testmethod void testaTrigger(){
        Case novoCaso = new Case();
        novoCaso.Nome__c = 'Teste';
        novoCaso.Status = 'Em aberto';
        novoCaso.Email__c = 'teste@teste.com';
        insert novoCaso;

        Comentario_caso__c novoComentario = new Comentario_caso__c();
        novoComentario.Caso__c = novoCaso.Id;
        novoComentario.Tipo_de_Comentario__c = 'Encerramento';
        insert novoComentario;   
        
        Case caso = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
        
        Test.startTest();
        System.assertEquals('Encerrado', caso.Status);
        Test.stopTest();
    }
}

Here is the Trigger
trigger AtualizaStatusDoChamado on Comentario_Caso__c (before insert, before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            List<Comentario_Caso__c> listaDeComentarios = trigger.new;
            Comentario_Caso__c novoComentario = listaDeComentarios[0];
            Case casoDoComentario = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
            if(novoComentario.Tipo_de_Comentario__c == 'Encerramento'){
                casoDoComentario.Status = 'Encerrado';
            }    
            System.debug('caso: ' + casoDoComentario);
        }
    }
}

Log
11:52:42:863 EXCEPTION_THROWN [19]|System.AssertException: Assertion Failed: Expected: Encerrado, Actual: Em aberto

On the Trigger, the debug is showing the correct Status, maybe I'm doing something wrong when trying to get the updated Case on Test Class.