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
Michelle SotoMichelle Soto 

System.DmlException: Failed to insert. First exception in row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER

I want to past the apex class test but when i validate the test class appear the next error:
 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because there was an error in the process “Caso nuevo”. Provide these details to your administrator Salesforce. null null : [] Stack Trace: Class.ActualizacionResolucionGeneralGarantiasT.actualizar: line 31, column 1

The flow “Caso nuevo” send a email alert. I think that the problem is the email of the contact, but in the test class i put the email in the contact.
 
@isTest
public class ActualizacionResolucionGeneralGarantiasT {
    @isTest
    static void actualizar(){
        ActualizacionResolucionGeneralGarantias actualizacion = new ActualizacionResolucionGeneralGarantias();
        Account cuenta = new Account(
        	Name = 'Test Account'
        );
        insert cuenta;
        Contact contacto = new Contact(
        	FirstName = 'User',
            LastName = 'Test',
            AccountId = cuenta.Id,
            Email = 'test@gmail.com'
        );
        insert contacto;
        case numeroCaso = new case(
            Subject = 'Test NO MOVER',
            AccountId = cuenta.Id,
            Dispositivo_Accesorio__c = 'ABC',
            Status = 'New',
            Priority = 'Low',
            ContactId = contacto.Id,
            Lista_de_dispositivos__c = 'Test NO MOVER',
            Origin = 'Phone',
            Dispositivos__c = '',
            Responsable__c = '0056g000005ixDtAAI',
            Producto_reportado__c = 'GO',
            Incidente_reportado__c = 'Otro'
        );
        insert numeroCaso;
    }
}
Thanks!
 
Best Answer chosen by Michelle Soto
mukesh guptamukesh gupta
Hi Michelle,

You should remove steps from test class, that's you are using in FLow criteria, i mean due to Insert of numeroCaso,  your folw should not be execute

For Example:-  suppose in flow you are using criteria Priority = 'Low' then you should not use in Test class 
Priority = 'Low' 

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

All Answers

PriyaPriya (Salesforce Developers) 

Hi Michelle,

On what condition your FLow trigger the emails ?

Thanks,

Priya Ranjan

mukesh guptamukesh gupta
Hi Michelle,

You should remove steps from test class, that's you are using in FLow criteria, i mean due to Insert of numeroCaso,  your folw should not be execute

For Example:-  suppose in flow you are using criteria Priority = 'Low' then you should not use in Test class 
Priority = 'Low' 

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
This was selected as the best answer
Michelle SotoMichelle Soto
¡Thanks mukesh gupta!

The issue is solved by changing the origin of the case, since depending the origin the flow run.