How To Create Dynamic Dependent Picklist Of Objects Within Salesforce
Another question has been asked to our Salesforce developers so we thought best to share it with the Salesforce development world. Dependent picklist is very useful within the Salesforce CRM for many reasons. It is used to limit the list of values in one picklist based on the value of another picklist.
An example would be if you had a list of continents, countries, states, regions and major cities. If you select a Continent as an example, you would want the country to be filtered in the next picklist within Salesforce. The country selected should then limit the states that would be available for selection and so on.
Displaying dependent picklists is very simple with a Visualforce page. Let’s assume that we have custom objects called continents, country, state, region and major cities. These are all the objects that are related to each other by the Lookup field within Salesforce.
In this simple example we are going to make 5 different objects within Salesforce. These will be continents, country, state, region and major cities. We will create 4 lookup fields as well. The first lookup field in country will be linked with continent, the second lookup field is state and is linked with country. The third lookup field is region and is linked with state and so on.
If you follow these simple steps within Salesforce, you can create a dynamic dependent picklist:
Step 1 –
Go To Setup a Develop a Apex Classes
Click the “New” button for creating new Apex class:
Copy this code and paste it in your editor
public class MultilevelDependentPicklist {public string conti{get; set;}public string contr{get; set;}public string stat{get; set;}public string regi{get; set;}public string city{get; set;}public MultilevelDependentPicklist(ApexPages.StandardController controller) { }public list<selectoption> getcontinentobj(){list<selectoption> options= new list<selectoption>();list<Continent__c> conti= [select name from Continent__c order by name];options.add(new selectoption(‘—-Select Anyone—-‘, ‘—-Select Anyone—-‘));for(Continent__c c:conti){options.add(new selectoption(c.name,c.name));}return options;
} public list<selectoption> getcontryobj(){ list<selectoption> options= new list<selectoption>(); list<Country__c> contr= [select name from Country__c where Continent__r.name=:conti]; options.add(new selectoption(‘—-Select Continent—-‘, ‘—-Select Continent—-‘)); for( Country__c c:contr){ options.add(new selectoption(c.name,c.name)); } return options; } public list<selectoption> getstateobj(){ list<selectoption> options= new list<selectoption>(); list<State_Provice__c> stat= [select name from State_Provice__c where Country__r.name=:contr]; options.add(new selectoption(‘—-Select Country—-‘, ‘—-Select Country—-‘)); for(State_Provice__c s:stat){ options.add(new selectoption(s.name,s.name)); } return options; } public list<selectoption> getregionobj(){ list<selectoption> options= new list<selectoption>(); list<County_Region__c> regi= [select name from County_Region__c where State_Provice__r.name=:stat]; options.add(new selectoption(‘—-Select State—-‘, ‘—-Select State—-‘)); for(County_Region__c r:regi){ options.add(new selectoption(r.name,r.name)); } return options; } public list<selectoption> getcityobj(){ list<selectoption> options= new list<selectoption>(); list<City__c> city= [select name from City__c where County_Region__r.name=:regi]; options.add(new selectoption(‘—-Select Region—-‘, ‘—-Select Region—-‘)); for(City__c c:city){ options.add(new selectoption(c.name,c.name)); } return options; } } |
Step 2 –
Go To Setup a Develop a Pages
Click the “New” button for creating new Visualforce pages within Salesforce
Step 3 –
In the label and name box type “Multi-level Dependent Picklist” within Salesforce
Step 4 –
In the Visualforce page editor paste this following code:
<apex:page standardController=”Continent__c” extensions=”MultilevelDependentPicklist”><apex:sectionHeader title=”Find your location” subtitle=”{!Continent__c.name}”/><apex:form ><apex:pageBlock title=”Location” mode=”edit”><apex:pageBlockSection columns=”1″><apex:pageblockSectionItem ><apex:outputLabel value=”Continent Name”/><apex:outputPanel styleClass=”requiredInput” layout=”block”><apex:outputPanel styleClass=”requiredBlock” layout=”block”/><apex:selectList size=”1″ value=”{!conti}”><apex:selectoptions value=”{!continentobj}”/><apex:actionSupport event=”onchange” reRender=”country”/></apex:selectList></apex:outputPanel>
</apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value=”Country Name”/> <apex:selectList size=”1″ value=”{!contr}” id=”country”> <apex:selectoptions value=”{!contryobj}”/> <apex:actionSupport event=”onchange” reRender=”states”/> </apex:selectList> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value=”State / Provice”/> <apex:selectList size=”1″ value=”{!stat}” id=”states”> <apex:selectoptions value=”{!stateobj}”/> <apex:actionSupport event=”onchange” reRender=”regions”/> </apex:selectList> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value=”County / Region”/> <apex:selectList size=”1″ value=”{!regi}” id=”regions”> <apex:selectoptions value=”{!regionobj}”/> <apex:actionSupport event=”onchange” reRender=”cities”/> </apex:selectList> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value=”City”/> <apex:selectList size=”1″ value=”{!city}” id=”cities”> <apex:selectoptions value=”{!cityobj}”/> <apex:actionSupport event=”onchange” reRender=”village”/> </apex:selectList> </apex:pageblockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> |
“Save” this code.
Step 5-
Check it and make sure it’s working correctly. Enjoy!
Creating dependent picklists within Salesforce are not very hard to. It is something that is very useful and can be used to make your life easier. We hope this has helped someone that is having trouble developing this within Salesforce. If you have any other Salesforce development questions or need anything else. Please feel free to reach out to the Mind Digital team anytime.
Follow us
Recent post
Popular post
- How To Call Batch Apex By Scheduler Class Within Salesforce
- What Is The Importance Of Google Algorithm Updates
- How To Create Dynamic Dependent Picklist Of Objects Within Salesforce
- What Is Wrapper Class & How To Use It In Salesforce
- How To Create Pagination Within Salesforce
- Tips For Hiring A Good Offshore Drupal Development Company
- Web Development Mistakes That Affect Your Online Reputation
- How To Integrate Google Maps Into Your Salesforce Software
- Check Your Link Building Strategy For 2014
- Tips For Selling Products Through Social Networking
- How To Create A Chart With Salesforce
- Benefits of Using India For Outsourcing & Offshore Development
- How To Integrate Salesforce With Facebook
- What Is Service Cloud Console In Salesforce & How To Enable It
- Superior Offshore Web Development At A Reasonable Cost
- How To Create Bucket Fields In Your Salesforce Reports
- 5 Things To Consider When Hiring A Drupal Developer
- Growth Of E-commerce Website Development
- Challenges In Hiring An Offshore Web Development Company
- 10 Tips When Creating Batch Apex In Salesforce
- What To Include & What To Exclude In SEO Plans
- How To Create An Opportunity Using A Visualforce Page In Salesforce
- Hire An Offshore Ruby On Rails Development Company Over A Freelancer
- Hire Drupal Developers Offshore To Increase Your Capabilities
- Effective SEO In A Post Panda Update – The Rules Have Changed
- Common Mistakes In Offshore Web Development
- What To Consider While Hiring A Dedicated Ruby On Rails Developer?
- Smart Phone & Tablet User Penetration
- Tips For Hiring A Good Offshore PHP Development Company
- Why Responsive Web Design Is Essential For Your Business
- How To Email Documents From Salesforce
- Website Development And Website Design Company India
- Why Work With An Offshore Development Company?
- How To Create Tab Panel In Salesforce
- How To Avoid 5 Common Off-Page SEO Mistakes
- The Multi-Billion Dollar Offshore Software Development Industry
- What Are The Advantages Of Digital Marketing Over Traditional Marketing?
- SEO & Conversational Keyword Search
- How To Avoid 5 Common On-Page SEO Mistakes
- How To Add Google Authorship And Its Benefits For Better SEO
- What’s Better For Facebook Ads: CPC Or CPM?
- Questions To Ask Your Potential Search Engine Optimization Partner
- How To Create Batch Apex In Salesforce
- Benefits Of Offshore PHP Development For Your Businesses
- Offshore Magento Development Means More Than Just Development Help
- Why You Should Consider Hiring Joomla Developers Offshore
- What To Look For When Hiring A Dedicated OpenCart Developer
- Stop Using Free Web Templates – Hire A Web Development Company
- How To Manage An Offshore Development Company?
- Hire Offshore Software Professionals To Help Your Business
- Offshore Development Is A Sensible Solution For Recessionary Times
- Why You Should Offshore Your Joomla Website Development
- 5 Tips To Help You Hire A Good Offshore PHP Development Company
- Reasons Why Salesforce CRM Customization Is Easy
- PHP Development – Turn Your Website Into A Multi-Featured Web Application
- 5 Things To Ask A Web Development Company Before Starting Work
- How A Multifaceted Web Development Company Can Help You?
- Take Advantage By Hiring A PHP Development Company From India
- Use Social Media Marketing To Improve Your Brand Identity
- Hiring Dedicated Developers From Offshore Development Companies
- See Measurable Results By Hiring Dedicated Ruby On Rails Developer
- Avoid 4 Common WordPress Development Mistakes
- Can “Developed By” Links Hurt Your SEO?
- How To Get All Salesforce Components In Force.com IDE
- The Manifold Advantages Of Working With An Offshore Web Development Company
- Web Development Company In India Defined
- Hire A Dedicated Drupal Developer To Develop A High Performance CMS
- Offshore Development – The Most Beneficial And Cost Effective Way To Outsource Your Business
- What To Look For When Hiring An Offshore Development Company
- Why Dedicated PHP Web Developers Are In Demand
- How To Avoid Some Common Mistakes When Working With An Offshore Web Development Company
- How To Choose An SEO Company
- Factors To Consider When Hiring Offshore Developers In India
- What To Look For When Hiring Dedicated Magento Developers
- Why Google Create Its Own Title Instead Of Using Yours
- 3 Challenges of Working with an Offshore Web Development Company
- Why Ruby On Rails Development Has Become Popular
- Why Hire A Web Development Company That Also Offers SEO
- 10 Tips And Tricks For Salesforce
- Are Back-links Losing Their Importance To Google Search Rankings
- The Significance Of A Salesforce Developer
- 4 Reasons to Hire A Web Development Agency Over A Freelancer
- Hire A PHP Developer- How Outsourcing Can Be A Key To Success
- Importance Of Strategic Digital Marketing For Business Growth
- Factors To Keep In Mind Before Hiring Dedicated Magento Developer
- Web Development India – For Prompt And Accurate Services
- Looking For An Offshore PHP Development Company, Where Do I Begin?
- 5 SEO Myths
- How To Choose A Company When Hiring Dedicated PHP Developers
- Why You Should Optimize For Local Search
- Hiring Offshore WordPress Developers Can Help Your Business
- How To Use Social Networking To Market Your Business
- Why Offshore Web Development To India Makes Business Sense
- 5 Factors To Consider When Hiring A Web Development Company
- Top Five Benefits Of Salesforce
- Benefits Of Hiring A Dedicated PHP Developer From India
- Using SEO & Social Media Together
- How Can An SEO Company Help Your Profile Online
- Strategic Importance Of Mobile SEO
- Choose The Social Media Network That Suits Your Business
Archives
- December 2024
- November 2024
- October 2024
- September 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- September 2023
- August 2023
- July 2023
- June 2022
- May 2022
- March 2022
- January 2022
- August 2021
- July 2021
- June 2021
- May 2021
- January 2021
- December 2020
- September 2020
- August 2020
- July 2020
- June 2020
- April 2020
- March 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- September 2018
- April 2018
- February 2018
- January 2018
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013