I have a screen flow on case record page. The flow starts with this screen - enter image description here

On clicking the Next button an apex action will run to check all the fields for null values. If there are fields with null values then a message is shown to the user to add values to those fields and a Finish button to restart the flow. enter image description here

If the Apex Action didn't find any null fields then a txt file is generated and added to the files related list of the case record.

enter image description here

Now everytime this flow is started or after clicking the Finish button on the above screen the flow will check for an existing file and if found the flow will provide the user with the below message. The issue I am having is while on this screen, if the users make a change to any of required fields like setting a field to null, the next step in the flow which is the Apex Action to check for null fields does not seem to pickup those fields with null values and it directly goes to the final screen which says the file has been generated. How do I have the Apex Action to pickup values in realtime.

enter image description here

Hoping I was able to explain the issue well.

UPDATE - Adding the Apex Action code -

    public with sharing class CheckForNullFieldsService {
    label='Check for Null Values Action'
    description='Method to check for null values in fields.'
  public static List<Results> checkForNullValues(List<Requests> input) {
    List<Results> results = new List<Results>();

    for (Requests request : input) {
      Results result = new Results();
      result.fieldsWithNullValues = '';
      result.status = 'Success';
      result.errorMessage = '';

      try {
        String caseId = request.caseRecord.Id;
        Case record = [
          FROM Case
          WHERE Id = :caseId
        Map<String, String> fieldsToCheck = new Map<String, String>{
          'SuppliedFirstName__c' => 'First Name',
          'SuppliedLastName__c' => 'Last Name',

        // Loop over the fields to check
        for (String fieldApiName : fieldsToCheck.keySet()) {
          // Check if the field value is null
          if (record.get(fieldApiName) == null) {
            String fieldName = fieldsToCheck.get(fieldApiName);
            result.fieldsWithNullValues += '• ' + fieldName + '\n';

        //Add the error message if any fields were null
        if (!String.isBlank(result.fieldsWithNullValues)) {
          result.errorMessage =
            'The following fields are required and cannot be left blank: \n' +
            result.fieldsWithNullValues +
            'Please provide valid values.';
          result.status = 'Error';
      } catch (Exception e) {
        result.status = 'Error';
        result.errorMessage = 'An error occurred: ' + e.getMessage();
      System.debug('result: ' + result);
    return results;
  public class Requests {
    @InvocableVariable(label='SObject API Name' required=true)
    public String sobjectApiName;

    @InvocableVariable(label='Case Record')
    public Case caseRecord;

    public WorkOrder workOrderRecord;

  public class Results {
    @InvocableVariable(label='Fields With Null Values' required=true)
    public String fieldsWithNullValues;

    @InvocableVariable(label='Status' required=true)
    public String status;

    @InvocableVariable(label='Error Message' required=true)
    public String errorMessage;

These are the case fields that the flow will check for null values -

enter image description here

After running through the flow once a validation file is generated and then now I am on this screen which is run at the beginning of the flow to check if a file already exists after clicking on the Finish to generate the validation file.

enter image description here

And now while on this screen if I remove the data for one of the fields, for e.g the Phone field as marked in the snip below, clicking on regenerate which will go through the null fields check again does not seem to pickup that field with null value and show it to the user. enter image description here

Here is the System.debug statement for the Phone field, the flow still uses the old value of that field.

enter image description here

And this is how the Apex action is setup in the flow -

enter image description here

Flow Diagram -

enter image description here

  • What exactly is the Apex Action doing? Can you edit the question to show the key parts - what it receives, what it returns and any queries that it does against the Case etc.
    – Phil W
    Jan 13 at 9:00
  • @PhilW I have added the apex action code. I know that the code works but as I mentioned it just doesn't pickup those changes happening to the record while the flow is in progress. The second screen snip is the result of the Apex action above. So I know it works.
    – sumchans
    Jan 13 at 9:06
  • I recognise the code from a previous question of yours. It is terribly inefficient. Instead of looping all fields from the schema, just loop through the ones you need to check, fetching just their schema detail, and only check them. Also note that the global schema describes method is very slow. Read this.
    – Phil W
    Jan 13 at 9:29
  • OK, so can you include a screenshot that shows the relationship between the record updates in the flow and the Case records you expect the Apex action to receive, and show how you call the Apex action (the detail for the call in the action element)?
    – Phil W
    Jan 13 at 9:30
  • @PhilW I have added as much details as I can.
    – sumchans
    Jan 13 at 17:27

1 Answer 1


You have a screen flow embedded in the Case record page. The flow is accepting a record with its fields on start. You are using this throughout the flow, including passing it to the Apex action.

As such, the flow is getting an in-memory copy of the record and its data when it starts and thus does not change when the record is concurrently updated in the record page.

You either need the flow to react to changes to the record (and I do not know of a way to do that) or you need to change the flow and/or the Apex action to use the Case record's ID to explicitly query the fields each time you need to use those values.

  • 1
    Thanks @Phil, I was thinking about the same and was lately trying to make the flow react to changes. And finally I ended up querying for the case fields.
    – sumchans
    Jan 13 at 20:33

You must log in to answer this question.

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