0

I am trying to pass 2 ID's into an apex action from a flow that just query's a subset of ID's and passes it back to the flow. I'm getting the following error for both my invocable variables inside the class: 'Variable does not exist: 'userId', 'Variable does not exist: 'projectId'

global class parseAssignmentShares {

    public class flowInputs {
    @InvocableVariable(required=true)
    public ID projectId;

    @InvocableVariable(required=true)
    public ID userId;
}
    @InvocableMethod (label = 'Enter Id(s)' description = 'Passes the Project and User Id into the apex class for a nested query.')
    public static List<pse__Assignment__Share> getProjectId (List<flowInputs> p){
    List<pse__Assignment__Share> shareIds = [SELECT Id 
                                             FROM pse__Assignment__Share 
                                             WHERE UserOrGroupId =:p.userId
                                             AND ParentId IN 
                                             (SELECT Id 
                                              FROM pse__Assignment__c 
                                              WHERE pse__Project__c =:p.projectId)];
     
        return shareIds;
    }

}

enter image description here

1 Answer 1

2

Welcome to Salesforce Stack Exchange (SFSE)!

It seems that the errors are on these lines:

WHERE UserOrGroupId =:p.userId
...
WHERE pse__Project__c =:p.projectId)];

p at this point is a List<flowInputs> not an individual flowInputs, so p.userId and p.projectId do not exist. You first need to iterate over your list:

for (flowInputs flowInput : p) {
    List<pse__Assignment__Share> shareIds = ...
        WHERE UserOrGroupId =:flowInput.userId
        ...
        WHERE pse__Project__c =:flowInput.projectId)];

Or better yet

List<Id> list_UserIds = new List<Id>();
List<Id> list_ProjectIds = new List<Id>();
for (flowInputs flowInput : p) {
    list_UserIds.add(p.userId);
    list_ProjectIds.add(p.projectId);
}
List<pse__Assignment__Share> shareIds = ...
    WHERE UserOrGroupId IN :list_UserIds
    ...
    WHERE pse__Project__c IN :list_ProjectIds)];

...unless you need the specific userId and projectIds to go together, in which case you could try to use Maps to help you not do individual SOQL queries inside a for loop.


I would also suggest naming your classes beginning with a capital letter, and name p something more descriptive (I like list_FlowInputs since Apex is strongly typed, but not everyone likes how I do it.)

You must log in to answer this question.

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