Oh my god. It's full of code!

28 responses

  1. Ben

    Boy… this made my day! Not even kidding… Been thinking about something like this for a project of mine.

    Let me know if you have any free time and want to take on some more mercenary work.



    February 23, 2012 at 8:53 pm

    • Hey there. Glad you liked it. I’m pretty busy for right now, but in a week or two I should have a bit more time to take on some work.

      February 23, 2012 at 8:55 pm

  2. Orn Ingvar

    Excellent work! Been looking/waiting for this for a long time now.

    We use dependent picklists to capture details in our cases where each record type has at least three dependent picklists that the call center reps need to fill out. Now I just need to figure out how I can use your code to display the picklists as a tree with something like jsTree and my reps will probably throw a ticker tape parade for me 😀

    February 24, 2012 at 10:59 am

  3. Awesome work Daniel! I find it ironic that JavaScript remoting has caused Force.com devs to return to the AJAX API to be able to do things like this — the more you dig into the AJAX API, the more you’re left scratching your head at things that Visualforce still doesn’t let you do without using their native components. There’s way too much functionality locked away in inputField / outputField that needs to be exposed to devs— with picklist / record type dependency info at the top of the list.

    March 5, 2012 at 2:37 pm

    • No doubt man, it’s crazy how deep into the bowels of the platform I had to dig to do this. It feels dirty and wrong, but I didn’t see any other way. Hopefully they give this issue a bit more attention in the future.

      March 12, 2012 at 9:18 pm

  4. Anand

    This is a really helpful solution. Used this back when dependent picklists were not supported in visualforce pages. The issue with the solution is that we won’t be able to use it in Sites pages as the API is disabled.

    March 12, 2012 at 9:14 pm

    • Hm, well in a pinch you may be able to make a visualforce page that prints out the options in JSON or XML format, then have your sites page invoke your visualforce page using a JSONP callback to extract the values and inject them in your picklist at run time?

      March 12, 2012 at 9:17 pm

      • Anand

        How do you expose the second visualforce page? As a sites page? If so, then the same limitation restricts it.

        March 13, 2012 at 7:43 pm

  5. Bhupendra

    Thanks buddy..I wanted same thing in my project….Working fine with three dependent picklists..


    May 4, 2012 at 1:51 pm

  6. Thank you Dan.
    It’s pretty damn cool, we were facing the problem in showing dependent picklist field in a visualforce page to which user was not having permission so were unable to use traditional way of handling dependent picklist. Your solution worked seemlessly!
    Thanks once again!!

    June 25, 2012 at 9:32 am

  7. mohit

    thats awesome , how diid … you ..
    awesome ……

    October 27, 2012 at 3:27 am

    • Haha thanks. It took quite a bit of hacking and playing around to figure this out. Glad you found it awesome as well.

      October 31, 2012 at 9:18 pm

  8. I tend not to drop a great deal of remarks, however I read a few of the remarks on Dependent Picklists in Salesforce
    without metadata API or Visualforce I Write Crappy
    Code. I do have some questions for you if it’s okay. Could it be just me or do a few of the responses look as if they are coming from brain dead individuals? 😛 And, if you are writing on additional online social sites, I would like to follow everything new you have to post. Could you post a list of the complete urls of your social sites like your Facebook page, twitter feed, or linkedin profile?

    November 29, 2012 at 9:53 am

  9. Greetings! I know this is somewhat off topic but I was wondering which blog platform are you using for this website?
    I’m getting sick and tired of WordPress because I’ve had problems with
    hackers and I’m looking at alternatives for another platform. I would be great if you could point me in the direction of a good platform.

    December 4, 2012 at 4:46 am

    • This is a wordpress blog. Thus far I haven’t had any issues aside from the occasional spam. I’d recommend it.

      December 4, 2012 at 5:19 am

  10. Anonymous

    Thank you, I was saved.

    January 31, 2013 at 8:34 am

  11. Anonymous

    Why do you need other scripts besides connection and how do you assign value to the salesforce apex variable?

    Thanks 🙂

    September 3, 2013 at 9:51 pm

  12. Praveen

    Not working in Internet Explorar . but it is really great. I have a suggestion. Please Put this is in Appexchange Package.

    September 5, 2013 at 2:18 pm

  13. I’ve used this in one of my pages and its working great, I never realised this code was part of this blog post as I had taken this code from another peer. Today when I came across this blog, thought of extending thanks for this piece. Nice way of getting dependant picklist values.

    However one concern, for every picklist onchange there’s being made one API call. So in my case its mutli-select picklist I’m showing in UI (though single select at object level) and on each of selection I make a call to this function (ie API call) to get corresponding dependant values. So as you see this method of getting dependant values is too API consuming and easily might end up in 10K of calls if you have 3-4 multi to multi picklist dependencies. Any suggestions here?

    Is there a way we can do same in Visualforce with hidden input fields ?

    January 31, 2014 at 10:00 am

  14. Anonymous

    It’s a miracle. I’m a big fan of your work 😀

    May 31, 2014 at 8:31 pm

  15. Anonymous

    I am stuck on something here. . . how do you pass the selected value into the controller class? do you have a quick solution?

    May 31, 2014 at 10:52 pm

  16. Toufik Atba

    Thanks for the tutorial it’s amazing !
    I wrote an equivalent code for java, i need the dependant picklists for an android app, however, it doesn’t work for me as expected, can you please take a look at this method :

    public boolean isDependentValue(int pos, String validFor) {
    byte[] validForDec = Base64.decode(validFor, Base64.DEFAULT);
    int at = pos >> 3;
    int bits = Character.codePointAt(byteArrayAsString(validForDec), at);
    return ((bits & (0x80 >> (pos%8))) != 0);

    public String byteArrayAsString(byte [] byteArray) {
    StringBuilder stringBuilder = new StringBuilder(byteArray.length);
    for(byte byteChar : byteArray)
    String s1 = String.format(“%8s”, Integer.toBinaryString(byteChar & 0xFF)).replace(‘ ‘, ‘0’);
    return stringBuilder.toString();

    Thank you 🙂

    June 22, 2014 at 1:02 pm

  17. Hi,
    I created More than one multipicklists in my object.How to display all multipicklists fields values as checkboxes Dynamically?

    help me………

    July 18, 2014 at 9:29 am

  18. Anonymous

    Can we have an option to export the picklist values for each controlling Field . please let me know the code

    March 31, 2015 at 7:33 am

  19. Anonymous

    Thank you for that code man, but there is something strange:

    This code always give me the dependant value of the previous value of the picklist:

    for(var item = 0; item < controllerFields.values.length; item++)
    if(controllerFields.values[item].value.toLowerCase() == value.toLowerCase())
    for(var i = 0; i < picklistValues.length; i++)
    if(isDependentValue(item, picklistValues[i].validFor))
    var newValue = new Object();
    newValue.label = picklistValues[i].label;
    newValue.value = picklistValues[i].value;
    newValue.default = picklistValues[i].defaultValue;
    newValue.validFor = picklistValues[i].validFor;
    newValue.validForName =controllerFields.values[item].value;

    I changed this:
    if(isDependentValue(item+1, picklistValues[i].validFor))

    And it works 😉

    February 16, 2016 at 5:06 pm

  20. Anonymous

    Heyy i am in thus situtation that i have 3 picklist picklist 1 picklist 2 and picklist 3 . Picklist 1 is controlling list for picklist 2 and picklist 2 is controlling field for picklist 3. Now i am able to fetch the picklist 2 dependent values based on picklist 1 controlling value. But problem is that on the basis of picklist 2 selectrd value i have to fetch picklist 3 depent values. The same function who return me picklist 2 depent value not returning picklist 3 dependent value for conttolling value from picklist 2

    August 13, 2016 at 3:25 am

    • Rahul

      I have been looking at this solution from past few weeks. great article I must say. However I am encountering one issue. the preview of this vf page gives me the solution while the same in the livechat doesn’t give me any solution. Could you please help me with it.

      August 1, 2017 at 7:50 pm

      • Rahul

        Just to elaborate my issues. Actually i am trying to capture dependent picklist in my live chat API. So Its working when I am trying as logged in user as teh value is being passed to session_Id. but whe the guest user clicks on it the session id is not passed. so the guest user or any visitor is not able to select the picklist values as it doenst populat to them. Could you please suggest me something so that guest user is able to see the picklist values. Any help would be great!!!

        August 2, 2017 at 9:48 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s