1

Had a problem where in the move to Lightning, we lost functionality with setting dependent picklist values. We wrote aura components but they don't allow default values for picklists to be defined, only default values for "normal" fields.. using the defaultFieldValues : objectWithFields

So, I thought I would try LWC but issue that I have found is that we are able to pass default values via import { CurrentPageReference } from 'lightning/navigation'; import { decodeDefaultFieldValues } from 'lightning/pageReferenceUtils';

And decode them, and then pass this into the objects, but for some reason the default value given to the dependent picklists does not work. You can pass default values for e.g. in this example, number of Employees, or, Name but when passing a default value e.g. “France” to a dependent field Country, this does not seem to work.

Does anyone have an example of where this works? Or can confirm this is a limitation of LWC similar to aura limitation?

I am following https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_navigate_default

I can put my own picklists. I am also concerned that we cannot set the recordType.. but hoping that it can be passed via the url.. but I'm also seeing this is difficult?

0

The problem is you cannot set the default value of dependent picklist even in field definition. Check this idea here:-

Enable Default Picklist Values on Dependent Picklists

Currently, if a picklist is the dependent field in a Field Dependency, its value will never be defaulted. This kinda makes sense when the field dependency restricts the default value from being an option. However, when the default value is an option, there's no logical reason for it not to be defaulted. This is true whether the default is set via record type or via the picklist field itself.

I tried and the results confirmed me.

enter image description here

enter image description here

This is the reason, default value for picklist field is not working via lwc as well.

To set the recordTypeId, you can do like this:-

this[NavigationMixin.Navigate]({
        type: 'standard__objectPage',
        attributes: {
            objectApiName: 'Contact',
            actionName: 'new'
        },
        state: {
            defaultFieldValues: defaultValues,
            recordTypeId: recordTypeId
        }
    });
2
  • In classic - regardless of how - I can see that we are setting default values for both the controlling and dependent picklist field so - this is functionality that WAS possible in visualforce/classic probably via URLs and hacking. But now with Lightning and with LWC despite everything we still can't get the dependent field to default. Even if you get the controlling field to default, perhaps a callback needs ot happen or somethingto do the dependent field. It is really not clear from the documentation.. – picklenic Jul 11 '20 at 10:24
  • update the controlling field default now works, but the dependent value still cannot be set by default. I think that there needs to be another call somewhere.. Working on this. – picklenic Jul 16 '20 at 0:19
0

Salesforce support said, what I want to do is not possible as of yet. So I will post the link from the IDEA back to here when I've raised it.

"As of now prefilling the values of the dependent picklist is not possible as of now.

For this to be implemented in future, I would suggest you to raise an idea in the idea exchange so that when it reaches the threshold value the product team will try to implement to it.

Link to the idea exchange : https://clicktime.symantec.com/3X8c8JSxJLCqs4zEoZsNVyE6H2?u=https%3A%2F%2Ftrailblazer.salesforce.com%2FideaSearch

Hope this helps."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.