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
Varun MKVarun MK 

The Data Type of the resource you entered doesnt match

I have an Apex Class that returns the Count of Number of times a User Logs into an Org. Further, this Apex class is called from a flow.

I am facing trouble when I am calling this Apex class in the Flow. I have attached the SS's.

While choosing the output parameter,
  1. What should be the variable choices ? simple variable or collection variable ?
  2. What should be the Data Type ?
  3. I am getting the error attacehd as "The Data Type of the resource you entered doesnt match"
  4. How can I Test this flow, it is intended to create a record and disable a user.
----------------------Apex Class:--------------------------------------

public class UserLoginCount {   
    @InvocableMethod
    public static List<List<Integer>> CountOfUserLogin(){  
        List<AggregateResult> lstSession = [SELECT COUNT_DISTINCT(LoginHistory.UserId) totalCount 
                                            FROM AuthSession 
                                            WHERE LoginHistory.UserId=:UserInfo.getUserId()];
        
        Integer countOfLogin = lstSession.size() > 0 ? Integer.valueOf(lstSession[0].get('totalCount')) : 0;       
        
        List<Integer> authSes = new List<Integer>();
        authSes.add(countOfLogin);
        
        List<List<Integer>> wrapList = new List<List<Integer>>();
        wrapList.add(authSes);  
        
        System.debug('Count'+wrapList);
        
        return wrapList;
        
        
    }
}
-----------------XXXXXXXXXXXXXX--------------------------------------------
User-added image

User-added image

User-added image

User-added image
#Flows #Apex
Raj VakatiRaj Vakati
The Inv


Inputs and Outputs
  1. There can be at most one input parameter and its data type must be one of the following:
  2. A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
  3. A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
  4. A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
If the return type is not Null, the data type returned by the method must be one of the following:
  • A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
  • A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
  • A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
  •  


Change your class as below and pass the list of user id from the flow 
 
public class UserLoginCount {   
    @InvocableMethod
    public static List<List<Integer>> CountOfUserLogin(List<Id> uId){  
        List<AggregateResult> lstSession = [SELECT COUNT_DISTINCT(LoginHistory.UserId) totalCount 
                                            FROM AuthSession 
                                            WHERE LoginHistory.UserId IN:uId ];
        
        Integer countOfLogin = lstSession.size() > 0 ? Integer.valueOf(lstSession[0].get('totalCount')) : 0;       
        
        List<Integer> authSes = new List<Integer>();
        authSes.add(countOfLogin);
        
        List<List<Integer>> wrapList = new List<List<Integer>>();
        wrapList.add(authSes);  
        
        System.debug('Count'+wrapList);
        
        return wrapList;
        
        
    }
}

 
Varun MKVarun MK
Thanks for the reply @Raj Vakati.

Could you suggest how I can test my flow? I was able to create a Collection variable with Number as the Data Type.