Contents[Hide]

Problem background.

We store Industry information on Account object in two fields, Industry and Subindustry.
Those fields have filed dependecy so when you select main industry you may have several subindutries to choose.

As we have about 20 main industries and 100 sub industries the Filed Dependeces map is qite big so it would take a lot of time to select that manually in dependeces map.

5 minutes solution

We will use Force IDE to copy picklist values and its dependeces.

1. Find the source

First find which are the source fields. I will base on those on Account object, it is: Industry (standard field) and Industry_subcategory__c (custom field)
.
Industry_subcategory__c is depended on Industry filed.

2. Create destination

I have created my custom object End_User__c which contains picklists: Industry__c and Industry_subcategory__c.
You do not need to copy values of picklisf fields leave them empty.

3. Open Force IDE and find already existing dependecy

Create new Project pointing to your Sandbox with metadata for "Objects - Standard" and "Objects - Custom".

Open file src/objects/Account.object and search for "Industry". You should find xml tags like below:

   <fields>
        <fullName>Industry</fullName>
        <picklist>
            ...
            <picklistValues>
                <fullName>Power Generation</fullName>
                <default>false</default>
            </picklistValues>
            ... 
            <picklistValues>
                <fullName>Other</fullName>
                <default>false</default>
            </picklistValues>
            <sorted>false</sorted>
            ...
        </picklist>
        <type>Picklist</type>
    </fields>

and

   <fields>
        <fullName>Industry_subcategory__c</fullName>
        <externalId>false</externalId>
        <label>Industry subcategory</label>
        <picklist>
            <controllingField>Industry</controllingField>
            ...
            <picklistValues>
                <fullName>Agricultural machinery</fullName>
                <controllingFieldValues>Other</controllingFieldValues>
                <default>false</default>
            </picklistValues>  
            ...
            <picklistValues>
                <fullName>Wind Energy</fullName>
                <controllingFieldValues>Power Generation</controllingFieldValues>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Sun Energy</fullName>
                <controllingFieldValues>Power Generation</controllingFieldValues>
                <default>false</default>
            </picklistValues>

          <sorted>false</sorted>
        </picklist>
        <trackFeedHistory>false</trackFeedHistory>
        <trackHistory>false</trackHistory>
        <type>Picklist</type>
    </fields>

As you can see structure is easy to understand. Industry picklist contains main categories. Then Industry_subcategory__c contains subcategories which are linked to value from Inustry by xml tag:

<controllingFieldValues>Power Generation</controllingFieldValues>

4. Modify fields on custom object

Now open your custom object, for me it is /src/objects/Und_User__c.object.

Find picklists Industry__c and Industry_subcategory__c it should be simillar to:

    <fields>
        <fullName>Industry__c</fullName>
        <externalId>false</externalId>
        <label>Industry</label>
        <picklist>
            <sorted>false</sorted>
        </picklist>
        <trackHistory>true</trackHistory>
        <type>Picklist</type>
    </fields>
    <fields>
        <fullName>Industry_subcategory__c</fullName>
        <externalId>false</externalId>
        <label>Industry subcategory</label>
        <picklist>
            <sorted>false</sorted>
        </picklist>
        <trackHistory>true</trackHistory>
        <type>Picklist</type>
    </fields>

Use first list to add values and dependeces from first one:

   <fields>
        <fullName>Industry__c</fullName>
        <externalId>false</externalId>
        <label>Industry</label>
        <picklist>
            ...
            <picklistValues>
                <fullName>Power Generation</fullName>
                <default>false</default>
            </picklistValues>
            ... 
            <picklistValues>
                <fullName>Other</fullName>
                <default>false</default>
            </picklistValues>
            <sorted>false</sorted>
            ...
        </picklist>
        <type>Picklist</type>
    </fields>

and

   <fields>
        <fullName>Industry_subcategory__c</fullName>
        <externalId>false</externalId>
        <label>Industry subcategory</label>
        <picklist>
            <controllingField>Industry__c</controllingField>
            ...
            <picklistValues>
                <fullName>Agricultural machinery</fullName>
                <controllingFieldValues>Other</controllingFieldValues>
                <default>false</default>
            </picklistValues>  
            ...
            <picklistValues>
                <fullName>Wind Energy</fullName>
                <controllingFieldValues>Power Generation</controllingFieldValues>
                <default>false</default>
            </picklistValues>
            <picklistValues>
                <fullName>Sun Energy</fullName>
                <controllingFieldValues>Power Generation</controllingFieldValues>
                <default>false</default>
            </picklistValues>

          <sorted>false</sorted>
        </picklist>
        <trackFeedHistory>false</trackFeedHistory>
        <trackHistory>false</trackHistory>
        <type>Picklist</type>
    </fields>

5. Save and delploy

Save it. Check if there are no problems reported.

Then right click on project choose Force.com -> Deploy to server... and deploy changes to production.

In my case it saved me about one hour of clicking throught dependecy table, reduced error rate caused by selecting to much or to less to 0, and reduced setting validation time to 0.

 

   
© Paweł Woźniak