0

I have an invocable method which is invoked when a platform event is published. So far the invocable method invokes on time and some elements of the data are extracted from the platform event.

Now when I do a SOQL based on one of the elements of the extracted data, I dont get any results at all. And when I do the same SOQL with the extracted data on the query editor of the developer console the right results are returned.

I did some system.debug statements to see if they are the right inputs for the SOQL and they all seem to be correct.

Here is my code. This code does not produce any results, it just does not return anything.

@InvocableMethod(label='Invocable Method')
    public static List<Results> processResponses(List<Requests> input) { 
        String fileName = input[0].fileName;
        String fileContent = input[0].fileContent;

        String patientIcn;

        List<String> fileContentSplits = fileContent.split('\n');
        for (String s: fileContentSplits) {
            if (s.startsWith('SID')) {
                List<String> sidSplits = s.split('\\^');
                for (Integer i = 0; i < sidSplits.size(); i++) {
                    if (i == 1) {
                        patientIcn = sidSplits[i];
                    }
                }
            }
        }
        System.debug('patientIcn -'+patientIcn); //This prints the right value

        List<WorkOrder> workOrder = [SELECT Id from WorkOrder WHERE Account.ICN__c =:patientIcn AND Status = 'Completed' LIMIT 1];
        System.debug(workOrder);//This has no results
        ContentVersion contentVersionFile = new ContentVersion();
        contentVersionFile.Title = fileName;
        contentVersionFile.PathOnClient = fileName;
        contentVersionFile.VersionData = Blob.valueOf(fileContent);
        contentVersionFile.ContentLocation = 'S';

        List<Results> results = new List<Results>();
        Results result = new Results();
        if (workOrder.size() > 0) {                      
            insert contentVersionFile;                 
            result.contentVersionFileId = contentVersionFile.Id;
            result.workOrderId = workOrder[0].Id;
            result.status = 'pass';

            results.add(result);
        }
        System.debug('Results-'+results);//This has no return as well.
        return results;
    }

I am doing some linking of the content document file after this invocable method is run and because the soql does not return anything the final linking process fails as well.

4
  • 1
    Please find out and state which user executes this query. Commented Dec 26, 2023 at 19:58
  • 2
    Also, is the invocable method class with or without sharing?
    – Phil W
    Commented Dec 26, 2023 at 20:14
  • @PhilW Can you put it as an answer please?
    – sumchans
    Commented Dec 27, 2023 at 2:37
  • 1
    @FelixvanHove Thanks for making me think in the right direction.
    – sumchans
    Commented Dec 27, 2023 at 2:38

1 Answer 1

1

The invocable method is Apex and exists in a class that can be with or without sharing. If it is the former, then the SOQL query will only return data to which the contextual user has sharing access.

This may be the reason you see no results - the contextual user for the flow execution has no sharing access to the records and so the query returns nothing.

You must log in to answer this question.

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