0

I have created two picklist values using metadata api and able to insert the values in the both the picklists, but I have to set the dependency between them, like one is controlling and other would be dependent. I don't want to do it manually.

Here is the code which is working fine to update the picklist values in the picklist fields. But having two issues.

  1. It is setting all the values inactive except the last one though I am setting isActive=TRUE for all the values.
  2. Not found anything to set the controlling and dependent picklist values.

    MetadataService.ValueSet picklistValueSet = new 
    MetadataService.ValueSet();
    MetadataService.ValueSetValuesDefinition valueDefinition = new 
    MetadataService.ValueSetValuesDefinition();
    List<MetadataService.CustomValue> values = new 
    List<MetadataService.CustomValue>();
    MetadataService.CustomValue customValue1 = new 
    MetadataService.CustomValue();
    
    customValue1.fullName = picklistValueFullname ;  // inserting from csv
    customValue1.isActive = TRUE;
    customValue1.default_x = FALSE;
    customValue1.label = picklistValueLabel; // inserting it from csv
    values.add(customValue1);
    
    valueDefinition.value = values;
    valueDefinition.sorted = false;
    
    picklistValueSet.valueSetDefinition = valueDefinition;
    
    customField.valueSet = picklistValueSet;
    
    List<MetadataService.SaveResult> results = service.createMetadata(new 
    MetadataService.Metadata[] { customField });        
    handleSaveResults(results[0]);
    
-1

Check the documentation here on controlling and dependent picklists:

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_field_types.html

and especially:

valueSet.controllingField

valueSettings.controllingFieldValue

It's tricky to set this up programmatically. I suggest setting up a dependent picklist in the Salesforce UI and then studying what that metadata looks like. Good luck.

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.