Skip to main content
2 of 7
added 107 characters in body
Eric
  • 54.4k
  • 11
  • 104
  • 196

So, leveraging the tooling API would be a lot of work.

Simplest way:

Per Adrian this may be another easy way but you would have to refactor the JS to apex:

Get lists of dependent picklist options in Apex

Apex Version (Code below is from link, I take no credit):

http://titancronus.com/blog/2014/05/01/salesforce-acquiring-dependent-picklists-in-apex/

public class Bitset{
        public Map<String,Integer> AlphaNumCharCodes {get;set;}
        public Map<String, Integer> Base64CharCodes { get; set; }
        public Bitset(){
            LoadCharCodes();
        }
        //Method loads the char codes
        private void LoadCharCodes(){
            AlphaNumCharCodes = new Map<String,Integer>{
                'A'=>65,'B'=>66,'C'=>67,'D'=>68,'E'=>69,'F'=>70,'G'=>71,'H'=>72,'I'=>73,'J'=>74,
                'K'=>75,'L'=>76,'M'=>77,'N'=>78,'O'=>79,'P'=>80,'Q'=>81,'R'=>82,'S'=>83,'T'=>84,
                'U'=>85,'V'=> 86,'W'=>87,'X'=>88,'Y'=>89,'Z'=>90    
            };
            Base64CharCodes = new Map<String, Integer>();
            //lower case
            Set<String> pUpperCase = AlphaNumCharCodes.keySet();
            for(String pKey : pUpperCase){
                //the difference between upper case and lower case is 32
                AlphaNumCharCodes.put(pKey.toLowerCase(),AlphaNumCharCodes.get(pKey)+32);
                //Base 64 alpha starts from 0 (The ascii charcodes started from 65)
                Base64CharCodes.put(pKey,AlphaNumCharCodes.get(pKey) - 65);
                Base64CharCodes.put(pKey.toLowerCase(),AlphaNumCharCodes.get(pKey) - (65) + 26);
            }
            //numerics
            for (Integer i=0; i<=9; i++){
                AlphaNumCharCodes.put(string.valueOf(i),i+48);
                //base 64 numeric starts from 52
                Base64CharCodes.put(string.valueOf(i), i + 52);
            }
        }
}

Second simple way:

  1. Create another object with fields
  • Master Value
  • Dependent Field API Name
  • Dependant Field Value
  1. Populate as appropriate
  2. Create a trigger to look up to this new object and set the values

Pros: Quick to implement

Cons: Maintenance - Have to remember to update this table when pick list values change. - NOT a best practice but given for those with minimal coding skills

Harder way:

  1. Use the tooling API and the describeLayout method to determine the pick list values based off of the master value.

Pros: None really given the above methods

Cons: Slow to implement and a lot of code required to start up. but there are examples you could possibly leverage

Eric
  • 54.4k
  • 11
  • 104
  • 196