Repository: appsmithorg/appsmith
File: app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java (Java)

Code before:
                    populatedExecuteActionDTO.setInstanceId(instanceId);
                    populatedExecuteActionDTO.setOrganizationId(organizationId);
                    return populatedExecuteActionDTO;
                }));
    }

    /**
     * Executes the action(queries) by creating executeActionDTO and sending it to the plugin for further execution
     *
     * @param partFlux
     * @param environmentId
     * @return Mono of actionExecutionResult if the query succeeds, error messages otherwise
     */
    @Override
    public Mono<ActionExecutionResult> executeAction(
            Flux<Part> partFlux, String environmentId, HttpHeaders httpHeaders, Boolean operateWithoutPermission) {
        ExecuteActionMetaDTO executeActionMetaDTO = ExecuteActionMetaDTO.builder()
                .headers(httpHeaders)
                .operateWithoutPermission(operateWithoutPermission)
                .environmentId(environmentId)
                .build();
        Mono<ExecuteActionDTO> executeActionDTOMono =
                createExecuteActionDTO(partFlux).cache();
        Mono<Plugin> pluginMono = executeActionDTOMono.flatMap(executeActionDTO -> newActionService
                .findById(executeActionDTO.getActionId())
                .flatMap(newAction -> pluginService.findById(newAction.getPluginId()))
                .cache());

        return pluginMono.flatMap(plugin -> {
            String pluginName = plugin.getName();
            executeActionMetaDTO.setPlugin(plugin);
            return executeActionDTOMono
                    .flatMap(executeActionDTO -> populateAndExecuteAction(executeActionDTO, executeActionMetaDTO))
                    .tag("plugin", pluginName)
                    .name(ACTION_EXECUTION_SERVER_EXECUTION)
                    .tap(Micrometer.observation(observationRegistry));
        });
    }

    /**
     * Fetches the required Mono (action, datasource, and plugin) and makes actionExecution call to plugin
     *
     * @param executeActionDTO
     * @param executeActionMetaDTO
     * @return actionExecutionResult if query succeeds, error messages otherwise
     */
    @Override
    public Mono<ActionExecutionResult> executeAction(
            ExecuteActionDTO executeActionDTO, ExecuteActionMetaDTO executeActionMetaDTO) {
        // 1. Validate input parameters which are required for mustache replacements
        replaceNullWithQuotesForParamValues(executeActionDTO.getParams());

Review comment (suggestion):
@ApekshaBhosale can you please add a check if newAction.getPluginId() is not null? 
You can also add error handling for switchIfEmpty() from both the findById() db calls

Code after:
                    }
                    populatedExecuteActionDTO.setInstanceId(instanceId);
                    populatedExecuteActionDTO.setOrganizationId(organizationId);
                    return populatedExecuteActionDTO;
                }));
    }

    /**
     * Executes the action(queries) by creating executeActionDTO and sending it to the plugin for further execution
     *
     * @param partFlux
     * @param environmentId
     * @return Mono of actionExecutionResult if the query succeeds, error messages otherwise
     */
    @Override
    public Mono<ActionExecutionResult> executeAction(
            Flux<Part> partFlux, String environmentId, HttpHeaders httpHeaders, Boolean operateWithoutPermission) {
        ExecuteActionMetaDTO executeActionMetaDTO = ExecuteActionMetaDTO.builder()
                .headers(httpHeaders)
                .operateWithoutPermission(operateWithoutPermission)
                .environmentId(environmentId)
                .build();
        Mono<ExecuteActionDTO> executeActionDTOMono =
                createExecuteActionDTO(partFlux).cache();
        Mono<Plugin> pluginMono = executeActionDTOMono.flatMap(executeActionDTO -> newActionService
                .findById(executeActionDTO.getActionId())
                .flatMap(newAction -> {
                    if (newAction.getPluginId() == null
                            || newAction.getPluginId().isEmpty()) {
                        return Mono.empty();
                    } else {
                        return pluginService.findById(newAction.getPluginId());
                    }
                })
                .cache());

        return pluginMono
                .map(plugin -> {
                    executeActionMetaDTO.setPlugin(plugin);
                    return plugin.getName() != null ? plugin.getName() : NONE;
                })
                .defaultIfEmpty(NONE)
                .flatMap(pluginName -> {
                    String name = (String) pluginName;
                    if (NONE.equals(name)) {
                        executeActionMetaDTO.setPlugin(null);
                    }
                    return executeActionDTOMono
                            .flatMap(executeActionDTO ->
                                    populateAndExecuteAction(executeActionDTO, executeActionMetaDTO))
                            .tag("plugin", name)