anusha(salesforce developer)

Thursday 19 January 2017

How To Create Dynamic Dependent Picklist Of Objects in Salesforce

Apex Code:

public class sample
{
    public String state {get;set;}
    public String city {get;set;}

    public List<SelectOption> getStates()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- None ---'));       
        options.add(new SelectOption('TN','Tamil Nadu'));
        options.add(new SelectOption('KL','Kerala'));
        return options;
    }
   
    public List<SelectOption> getCities()
    {
        List<SelectOption> options = new List<SelectOption>();
        if(state == 'TN')
        {      
            options.add(new SelectOption('CHE','Chennai'));
            options.add(new SelectOption('CBE','Coimbatore'));
        }
        else if(state == 'KL')
        {      
            options.add(new SelectOption('COA','Coachin'));
            options.add(new SelectOption('MVL','Mavelikara'));
        }
        else
        {
            options.add(new SelectOption('None','--- None ---'));
        }     
        return options;
    }      
}


Visualforce page:

<apex:page controller="sample">
   
    <apex:form >
   
    <apex:pageBlock>
        <apex:pageBlockSection columns="2">
            <apex:pageblockSectionItem>
                <apex:outputLabel value="State"/>
            </apex:pageblockSectionItem>       
            <apex:pageblockSectionItem>               
                <apex:selectList size="1" value="{!state}">
                    <apex:selectOptions value="{!states}"/>
                    <apex:actionSupport event="onchange" reRender="a"/>
                </apex:selectList>               
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem>
                <apex:outputLabel value="City"/>
            </apex:pageblockSectionItem>           
            <apex:pageblockSectionItem>
                <apex:selectList size="1" value="{!city}" id="a">
                    <apex:selectOptions value="{!cities}"/>
                </apex:selectList>
            </apex:pageblockSectionItem>           
        </apex:pageBlockSection>       
    </apex:pageBlock>

    </apex:form>

</apex:page>

22 comments:

  1. Thanks a lot for sharing that useful information. That was a really Intresting post and I would really like to know more.

    salesforce development company
    Salesforce development services
    Salesforce Consultant

    ReplyDelete
  2. Good article - Lexicon Infotech a Salesforce registered consulting partner

    ReplyDelete
  3. Well Post! Thank you so much for sharing this make attractive post, it was so nice to read and useful to improve myself knowledge as updated one, keep blogging
    Saleforce Admin Training in Electronic City

    ReplyDelete
  4. Find Here Best Salesforce Certification Sample Papers, Platform Developer 1 Dumps, We are Providing Salesforce Sample Questions, Salesforce Dumps, Service Cloud Sample Papers, Sales Cloud Sample Papers, We have online courses for Salesforce Administrators as well as Developer Certification. Details of the same are available.

    Bundle Offer 2020:

    We are new offering. Buy any two papers and get third free. Offer available for for all courses available online. You can pick and choose certifications which are relevant to you and complete the certifications at your pace.

    More Info: http://www.salesforcecertifications.com/

    ReplyDelete
  5. Very well written article. It was an awesome article to read
    Salesforce Integration Services

    ReplyDelete
  6. Thanks for sharing post. It is easy to understand to create dynamic dependent picklist of objects in Salesforce.
    Salesforce Integration Services

    ReplyDelete
  7. Thanks a lot for explaining practically.
    Really Appreciable!
    Admin Guide to Export Field Permissions for Permission Sets using BOFC

    ReplyDelete
  8. Nice article!
    I found many useful information in your blog, it was awesome to read,thanks for sharing this great content, keep sharing..
    Create Multiple Validation Rules for multiple objects

    ReplyDelete
  9. This post is really nice and informative. The explanation given is really comprehensive and informative.
    Salesforce App Development

    ReplyDelete

  10. Thanks, this is generally helpful.
    Still, I followed step-by-step your method in this salesforce cpq online training
    salesforce cpq course

    ReplyDelete
  11. 360degreecloud is a certified Salesforce ISV partner that has years of experience in successfully developing and integrating Salesforce solutions for clients from all over the world. Moreover, team consists of certified professionals who have years of experience behind their back.

    visit-360degreecloud

    ReplyDelete
  12. Thanks for sharing post. It is easy to understand Salesforce through this post.To know more about Salesforce Visit Webnersolutions!

    ReplyDelete
  13. "With more than 8 years of experience in Salesforce support, Sales Cloud services we’re the Salesforce Implementation Partner of choice to meet business needs. 360 Degree Cloud is a Salesforce Certified Consulting Partner that
    offers Salesforce Consulting, Implementation and Integration services"

    visit-360degreecloud

    ReplyDelete
  14. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.
    CPQ Sales Force Training
    Visit us: sales force CPQ Online Training

    ReplyDelete
  15. Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog.
    Choose ACAP, the top-rated Salesforce development company for small businesses. ACAP’s certified Salesforce developer consultants specialize in customization, migration and integration of award-winning, affordable solutions.

    ReplyDelete
  16. this blog is beneficial and great information to share with us. Iqra Technology is an IT Solutions and Services Company more information visit to our web site iqratechnology
    hire-salesforce
    salesforce-admin
    salesforce-development

    ReplyDelete

  17. MR Reporting Mobile App is now even more user friendly ensuring a delightful experience on mobile while Tracking DCR, TP, Expense status viewing and much more. CBO ERP Ltd provides best reporting software for pharma and MR/ Online Mobile MR Reporting software, Some Key Features Of “Pharma Mobile/Tablet MR Reporting Software” are as under:

    • Easy and fast reporting.
    • Acute & error free.
    • No waiting for the salary process.
    • No waiting for expense data.
    • No need to carry a visual aid inbuilt detailing system.
    • Non submitted DCR information by SMS to H.O. / Managers.
    https://www.cboerp.com/mr-reporting-software.php

    ReplyDelete