0

I'm having difficulty finding a way to write the syntax to set my invocable variables in the test class: Here's the code.

global class EmailPreventivoAccettato {
global class Parametri {
    @InvocableVariable(required=true)
    public string IDPreventivo;
    @InvocableVariable(required=true)
    public string Gruppo;
}

this class is called by a method that send an e-mail:

@InvocableMethod(label='Invia preventivo in allegato (.csv)')
public static void SpedisciMail(Parametri[] inputs) {

I wrote the test class:

EmailPreventivoAccettato.Parametri[] Parametri = new EmailPreventivoAccettato.Parametri[]{};
Parametri[0].IDPreventivo = '0Q03E000000I5OLSA0';
Parametri[0].Gruppo = 'TEST';
EmailPreventivoAccettato.SpedisciMail(Parametri);

but It return me an error when I run the test:

System.ListException: List index out of bounds: 0

someone can help me?...

1
  • You List is empty and youre attempting to get [0] element of it Oct 1, 2019 at 13:14

2 Answers 2

2

Your problem has nothing to do with invocable variable.

You are trying to access the 0 index element immediately after creating instance Parametri in test class. You should add element in list instead. Try below:

EmailPreventivoAccettato.Parametri Parametri1 = new EmailPreventivoAccettato.Parametri();
Parametri1.IDPreventivo = '0Q03E000000I5OLSA0';
Parametri1.Gruppo = 'TEST';

EmailPreventivoAccettato.Parametri[] Parametri = new EmailPreventivoAccettato.Parametri[]{};
Parametri.add(Parametri1);
EmailPreventivoAccettato.SpedisciMail(Parametri);
1

You have created the list, but not an Object in it, change your code a bit:

EmailPreventivoAccettato.Parametri ParametriObj = new EmailPreventivoAccettato.Parametri();
ParametriObj.IDPreventivo = '0Q03E000000I5OLSA0';
ParametriObj.Gruppo = 'TEST';
EmailPreventivoAccettato.SpedisciMail(new List<EmailPreventivoAccettato.Parametri>{ParametriObj});
1
  • 1
    Thank You for the reply! I solved the problem :) Oct 1, 2019 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .