Ensuring Field Value is Available Before Filtering Picklist?

Ensuring Field Value is Available Before Filtering Picklist?

On February 11, 2026, Posted by , In LWC Essentials,Salesforce Technical Questions, With Comments Off on Ensuring Field Value is Available Before Filtering Picklist?
Ensuring Field Value is Available Before Filtering Picklist

Question:

I have a Lightning Web Component (LWC) that displays a custom path. The component relies on a record field value to determine which picklist values should be displayed. However, I am encountering an issue where the field value is not available when the picklist filtering logic runs.

The component uses @wire(getRecord, getFieldValue) to retrieve the field value and @wire(getPicklistValues) to fetch picklist options. Since both wire adapters run asynchronously and in parallel, there is no guarantee that getRecord will complete before getPicklistValues. As a result, the filtering logic may execute before the field value is available, causing incorrect or incomplete picklist options to be displayed.

Result

How can I ensure that the field value is retrieved first before the picklist filtering logic executes?

Answer

Since @wire functions execute independently and asynchronously, you cannot enforce an execution order between getRecord and getPicklistValues. However, you can synchronize their results by using flags to track when both wire adapters have completed, and then trigger the filtering logic only when both values are available.

Master Salesforce with expert-led salesforce online training at CRS Info Solutions—join our demo session now!!!

In the solution below, we introduce a method called initializeStageOptions() that runs only when both getRecord and getPicklistValues have finished loading. The method is triggered at the end of both wired functions, ensuring that the filtering logic executes only after the field value is retrieved.

import { LightningElement, wire, api, track } from "lwc";
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
import { getPicklistValues } from "lightning/uiObjectInfoApi";
import REGISTRY_TRANSFER from "@salesforce/schema/RegistryTransfer__c";
import REGISTRY_TRANSFER_SETTLEMENT_STATUS from "@salesforce/schema/RegistryTransfer__c.Settlement_Status__c";
import ISSUE_CONTRACT_ACCEPTANCE from "@salesforce/schema/RegistryTransfer__c.Issue__r.Contract_Acceptance__c";

const FIELDS = [ISSUE_CONTRACT_ACCEPTANCE];

export default class RegistryTransferPath extends LightningElement {
    @api objectApiName;
    @api recordId;
    stageOptions;
    settlementStatus;
    @track record;
    @track acceptance;

    currentStep = "slds-path__item slds-is-current";
    completeStep = "slds-path__item slds-is-active";
    incompleteStep = "slds-path__item slds-is-incomplete";

    @wire(getRecord, { recordId: "$recordId", fields: FIELDS })
    wiredRT({ error, data }) {
        if (data) {
            this.record = data;
            this.acceptance = getFieldValue(this.record, ISSUE_CONTRACT_ACCEPTANCE);
            this.error = undefined;
            this.initializeStageOptions();
        } else if (error) {
            this.error = error;
            this.record = undefined;
        }
    }

    @wire(getObjectInfo, { objectApiName: REGISTRY_TRANSFER })
    registryTransfer;

    @wire(getPicklistValues, {
        recordTypeId: "$registryTransfer.data.defaultRecordTypeId",
        fieldApiName: REGISTRY_TRANSFER_SETTLEMENT_STATUS
    })
    picklistValues({ data }) {
        if (data) {
            this.settlementStatus = data;
            this.initializeStageOptions();
        }
    }

    initializeStageOptions() {
        if (!this.record || !this.settlementStatus) {
            return;
        }

        let increment = 1;
        const isAcceptanceEnabled = this.acceptance === "Enabled" || !this.acceptance;

        this.stageOptions = this.settlementStatus.values
            .filter(
                (item) =>
                    isAcceptanceEnabled ||
                    (item.value !== "Awaiting Approval" && item.value !== "Contract Acceptance")
            )
            .map((item) => {
                return {
                    position: increment++,
                    value: item.value,
                    pathStatus: this.incompleteStep,
                    tickIcon: false
                };
            });
    }
}

Explanation:

This Lightning Web Component (LWC) retrieves a record’s field value and picklist values to dynamically filter and display a custom path. It uses @wire(getRecord) to fetch the Contract_Acceptance__c field and @wire(getPicklistValues) to retrieve picklist options, ensuring that both are available before applying filtering logic. The initializeStageOptions() method waits until both data sources are loaded before setting stageOptions, preventing premature execution and ensuring accurate filtering.

This solution ensures that both getRecord and getPicklistValues complete before stageOptions is populated. The initializeStageOptions() method acts as a guard, preventing execution until both data sources are available.

Accelerate Your Career with Salesforce Training in Mumbai

Are you ready to elevate your career in Mumbai’s thriving Salesforce ecosystem? At CRS Info Solutions, we offer Salesforce online training  that equips you with the skills to stand out. Our comprehensive program, led by experienced industry professionals, covers essential areas like Salesforce Administration, Development, and cutting-edge AI modules. With a focus on hands-on learning and real-time projects, you’ll gain practical expertise to tackle real-world challenges confidently.

Whether you’re embarking on your Salesforce journey or aiming to enhance your skill set, our tailored training programs are designed to meet your unique needs.  Salesforce training in Mumbai From mastering certification requirements to acing job interviews, we provide personalized guidance, in-depth course materials, and expert strategies for success.

Join our free demo session today and take the first step toward a prosperous Salesforce career in Mumbai!!!

Comments are closed.