• anajli sharma
  • NEWBIE
  • -1 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    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.
Is there a way to refresh the data in a lightning datatable after making an update via an apex class?

Hi,

 

We have a 3rd party webserivce that send leads from our site to SF with Lead Owner already assigned based on some coded rules. We now want to add a level of lead assignment above what this can handle, so I wrote a lead assignment rule and have activated it.

 

The rules seem to be completley ignored as leads are coming in, but work if a lead is edited and saved ticking the "use active assignmnet rules" checkbox. (i.e the lead assignment crieria works, but its not being triggered)

 

So I thought a trigger to re-run lead assignment directly after a lead has been created would be the only solution, issue is I have no coding experience (aside from one easy update trigger some guys on here helped with!)

 

Can anyone help? Or if another solution exists that woudl be great too!

 

Antony