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
EvertonSzekeresEvertonSzekeres 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Hi !

When I try to deploy my trigger. I'm getting this error:

Run Failures:
Email_abertura_de_vaga_test.myUnitTest001 System.DmlException: Update failed. First exception on row 0 with id 500U0000009g8I5IAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Email_abertura_de_vaga_case: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

My trigger:

trigger Email_abertura_de_vaga_case on Case (after update) {

  
for(Case c : trigger.new){
    if (c.Func_abertura_chamado__c == 'THIAGO MARTINS' && c.motivo__c == 'Abertura de vaga' && c.resposta__c != null){

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          String[] toAddresses = new String[]{};  
            toAddresses.add('thiago.martins@cp7.com.br');
          mail.setToAddresses(toAddresses);
         
            mail.setSenderDisplayName('Vaga finalizada');
           
            mail.setreplyto ('alessandra.gomes@cp7.com.br');        
           
          mail.setSubject(''+c.Nome_atendimento__c+'');
          mail.setHtmlBody('Olá, tudo bem '+c.Func_abertura_chamado__c+'?<p>Segue informações de seu novo funcinário:</p><p><b>Vaga:</b> '+c.N_veis__c+'</p><p><b>Solicitante da vaga:</b> '+c.Func_abertura_chamado__c+'</p><p><b>Data de abertura da vaga:</b> '+c.CreatedDate.day()+'/'+c.CreatedDate.month()+'/'+c.CreatedDate.year()+'</p><p><b>Meios de divulgação:</b> '+c.Meios_de_divulga_o__c+'</p><p><b>Número de candidatos agendados:</b> '+c.Candidatos_agendados__c+'</p><p><b>Número de candidatos avaliados:</b> '+c.Candidatos_avaliados__c+'</p><p><b>Número de candidatos pré-selecionados:</b> '+c.Candidatos_pr_selecionados__c+'</p><p><b>Data de fechamento:</b> '+c.ClosedDate.day()+'/'+c.ClosedDate.month()+'/'+c.ClosedDate.year()+'</p><p><b>Candidato contatado:</b> '+c.Nome_atendimento__c+'</p><p><b>Data de início:</b> '+c.In_cio__c.day()+'/'+c.In_cio__c.month()+'/'+c.In_cio__c.year()+'</p><p><b>Observações:</b> '+c.resposta__c+'</p>');
           
          Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
      }
...



My test class:

@isTest (seeAllData=true)
public class Email_abertura_de_vaga_test {

static testMethod void myUnitTest001() {

Case ct = new Case();
    ct.Func_abertura_chamado__c = 'EVERTON GOMES';
    ct.motivo__c='Abertura de vaga';
    ct.subject='test';
    ct.Description='test test';
    ct.Nome_atendimento__c='Asassa';
    ct.N_veis__c='Auxiliar';
    ct.Meios_de_divulga_o__c='Asdfgh';
    ct.Candidatos_agendados__c=15;
    ct.Candidatos_avaliados__c=9;
    ct.Candidatos_pr_selecionados__c=1;
    ct.resposta__c=null;
insert ct;

ct.resposta__c='teste'; ct.Func_abertura_chamado__c = 'THIAGO MARTINS'; ct.motivo__c='Abertura de vaga';
ct.Nome_atendimento__c='Teste';
    ct.N_veis__c='Recepcionista';
    ct.Meios_de_divulga_o__c='TEste';
    ct.Candidatos_agendados__c=12;
    ct.Candidatos_avaliados__c=10;
    ct.Candidatos_pr_selecionados__c=2;
update ct;
     
}
Best Answer chosen by EvertonSzekeres
Satyendra RawatSatyendra Rawat
Hi,

set the value to the custom field "In_cio__c".
CT.
In_cio__c = Date.today();
after assignation you can insert and update the record. Because You have used in "c.In_cio__c.month()" , 
c.In_cio__c initialize with null.


All Answers

Satyendra RawatSatyendra Rawat
Hi,

set the value to the custom field "In_cio__c".
CT.
In_cio__c = Date.today();
after assignation you can insert and update the record. Because You have used in "c.In_cio__c.month()" , 
c.In_cio__c initialize with null.


This was selected as the best answer
EvertonSzekeresEvertonSzekeres
Thanks !

I don't know whats happened.
The first time I tried this, It didn't work.

Now it's perfect.
Thanks again !