0

How to assign a default value for a dependent picklist field in salesforce lightning . I am unable to assign a default value for dependent picklist field in lightning .

cmp

<aura:component implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global">



     <aura:attribute name="record" type="Object"
                    description="The record object to be displayed"/>
    <aura:attribute name="PolicyRecord" type="Object"
                    description="A simplified view record object to be displayed"/>
    <aura:attribute name="recordError" type="String"
                    description="An error message bound to force:recordData"/>    

    <aura:attribute name="minor" type="String" />
    <force:recordData aura:id="record"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetError="{!v.recordError}"
                      targetRecord="{!v.record}"
                      targetFields="{!v.PolicyRecord }"
                      mode="VIEW"/>


    <lightning:button label="New Claim" variant="brand" onclick="{!c.CreateClaim}" />

    <!--aura:handler name="init" value="{!this}" action="{!c.doInit}" /-->
</aura:component>

Controller:

({
    CreateClaim : function(component, event, helper) {

      var coverageMinor = component.get("v.PolicyRecord.Coverage_Minor__c");

       component.set("v.minor",coverageMinor);
        var minorAttribute = component.get("v.minor");
        console.log("test2:"+coverageMinor);
        console.log("v.minor:"+minorAttribute);

        var createRecordEvent = $A.get('e.force:createRecord');
       if( createRecordEvent ){
            createRecordEvent.setParams({
                'entityApiName' : 'Claim__c',
                'recordTypeId': component.get("v.PolicyRecord.Record_Type_Formula__c"),
                'defaultFieldValues' : {

                    'Coverage_Major__c'  : component.get("v.PolicyRecord.Coverage_Major__c"),
                    'Policy_Lookup__c' : component.get("v.recordId"),
                    'Location_Lookup__c' : component.get("v.PolicyRecord.Hierarchy_Level__r.Id"),
                    'Coverage_Minor__c' : component.get("v.PolicyRecord.Coverage_Minor__c") // dependent picklist

                },
            });

           createRecordEvent.fire(); 
        }


    },
    onRecordUpdated : function (component, event, helper) {
    var changeType = event.getParams().changeType;
    if(changeType === "CHANGED") {
    component.find("recorddata").reloadRecord();
}
}
})
  • Can you show the code that you tried? – salesforce-sas Oct 29 '19 at 7:57
  • i have given my code as an answer . Please check it and suggest . The dependent picklist is not setting the default value . Thank you – prudhvi tej Oct 29 '19 at 9:10

Your Answer

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

Browse other questions tagged or ask your own question.