1

I'm having an issue with a flow and an apex invocable action I want to add.

this is my apex class:

public without sharing class EnsayosRedPropiaConVentasCRMAction {

@InvocableMethod(label = 'Validar Red Propia si tienen ventas CRM' description = 'Devuelve las listas de productores con licencias aprobadas sin ventas CRM o con ventas CRM como originante o destinatario')
public static List<ValidacionRedPropiaResult> obtenerListasProductores(List<String> productores){

    Set<Id> productoresIds = new Set<Id>();
    for(String productorId : productores){
        productoresIds.add(Id.valueOf(productorId));
    }

    Set<Id> productoresConVentasOriginante = new Set<Id>();
    for(Venta__c ventaCrmOriginante : [SELECT Id, Originante__c FROM Venta__c WHERE Semba_Evolucion__c = true AND Originante__c IN :productores]){
        productoresConVentasOriginante.add(ventaCrmOriginante.Originante__c);
    }

    Set<Id> productoresConVentasDestinatario = new Set<Id>();
    for(Venta__c ventaCrmDestinatario : [SELECT Id, Destinatario__c FROM Venta__c WHERE Semba_Evolucion__c = true AND Destinatario__c IN :productores]){
        productoresConVentasDestinatario.add(ventaCrmDestinatario.Destinatario__c);
    }

    productoresIds.removeAll(productoresConVentasDestinatario);
    productoresIds.removeAll(productoresConVentasOriginante);

    ValidacionRedPropiaResult result = new ValidacionRedPropiaResult();
    result.productoresConVentasCrmOriginante = new List<Id>(productoresConVentasOriginante);
    result.productoresConVentasCrmDestinatario = new List<Id>(productoresConVentasDestinatario);
    result.productoresSinVentasCrm = new List<Id>(productoresIds);

    return new List<ValidacionRedPropiaResult>{result};
}

public class ValidacionRedPropiaResult {
    @InvocableVariable(label = 'Productores sin ventas CRM' )
    public List<Id> productoresSinVentasCrm;
    
    @InvocableVariable(label = 'Productores con ventas CRM como originante')
    public List<Id> productoresConVentasCrmOriginante;

    @InvocableVariable(label = 'Productores con ventas CRM como destinatario')
    public List<Id> productoresConVentasCrmDestinatario;
}

}

The input parameter was defined as a List of Ids before, and then I changed it to List of string.

The collection variable from the flow I am using is defined like this: enter image description here

I understand that is a collecton of Strings. But, when I try to assign that variable as input, the flow throws an incompatible data type error:

enter image description here

Am I missing something? I believe my apex is correct, and the variable from the flow is indeed a collection of strings so why is it incompatible?

1 Answer 1

3

Your error is that the flow interview assumes the input to the invocable is a collection of strings but the invocable is expecting each interview to supply only a single string

Invocable apex is bulkified

Hence, an argument of

public static List<ValidacionRedPropiaResult> obtenerListasProductores(List<String> productores){

means each interview supplies a scalar string.

But if your flow wants to supply a collection of strings for each interview, then the invocable needs to look like this:

public static List<ValidacionRedPropiaResult> 
     obtenerListasProductores(List<String[]> productores){

that is, a list of list of strings.

Invocables are always bulkified, even if associated to a screen flow where the number of interviews is 1.

1
  • That is exactly it, I just figured it out before reading your answer, thanks a lot ! Apr 18 at 16:30

You must log in to answer this question.

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