-
How to display picklist values based on Lookup value on VF page in Salesforce?
I created a custom VF page to create custom object record. I have a Account lookup on page.
So whenever a user selects value from the lookup I would like to show dynamic picklist options on VF page by querying with LookupID for example I want to show names on dropdown, queried from selected lookup Id before saving the record.
Class:
public class createPriceRecord
{
public Price__c price{get; set;}
public Price__c priValue;
public Id lookupId{get;set;}
public Price__c ReqOpp;public createPriceRecord (ApexPages.StandardController controller) {
price= (Price__c)controller.getRecord();
stdCtrl=controller;
}
private ApexPages.StandardController stdCtrl;public void AccPopulated()
{
priValue= (Price__c)stdCtrl.getRecord();
}public List<selectOption> getselectValues()
{
List<Prod__c> relatedprod = new List<Prod__c>();relatedprod = [Select Id,name from Prod__c where AccLookup__c.id =: priValue.Account__r.ID ]; // trying to get Account id from VF page
List<SelectOption> Options = new List<SelectOption>();
Options.add(new SelectOption('','-None-'));
for(Prod__c prod:relatedprod)
{
Options.add(new SelectOption(prod.Id,prod.Name));
}
return Options;
}public PageReference SaveRec(){
price.Look_Up__c = lookupId;
insert price;PageReference p=new PageReference('my.salesforce.com/'+price.Id);
return p;}
}
Page:
<apex:page standardController="Price__c" extensions="createPriceRecord" tabStyle="Price__c">
<apex:form >
<apex:pageBlock title="Price Edit" mode="edit">
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!SaveRec}"/>
</apex:pageBlockButtons><apex:pageBlockSection columns="2" title="Price Information">
<apex:inputField value="{!price.AccountId}">
<apex:actionSupport event="onchange" action="{!AccPopulated}" immediate="true" />
</apex:inputfield><apex:selectList value="{!lookupId}" title="Select" multiselect="false" size="1" >
<apex:selectOptions value="{!selectValues}"/>
</apex:selectList><apex:inputField value="{!price.name}"/>
</apex:PageBlockSection>
</apex:pageBlock>
</apex:form >
</apex:page>
Log In to reply.
Popular Salesforce Blogs
![](https://images.forcetalks.com/wp-content/uploads/2022/05/05051550/sa_1651727738peopleanalyzinggrowthcharts_232148866844.jpg)
Top 7 Salesforce Trends For 2022
Every technology we know is updating itself rapidly. If you do not keep an eye on the new additions, you might miss some amazing benefits…
![](https://images.forcetalks.com/wp-content/uploads/2019/02/14102401/FT-Banners-71-38.jpg)
Single or Multi-Org - What is your Salesforce Architecture?
While setting up a Salesforce Architecture or assessing the performance of an existing org, the most perplexing question that haunts anyone is to decide between…
![Flow Builder in Salesforce](https://images.forcetalks.com/wp-content/uploads/2022/10/26184358/Flow-Builder-in-Salesforce.jpg)
Flow Builder in Salesforce - Here's All You Need to Know About
Flow is a Salesforce application that automates difficult business procedures. In other words, it gathers data and uses the data for our business logic. One…
Popular Salesforce Videos
What is Salesforce Integration? | Saleforce Integration Explained
Learn how to seamlessly connect different tools and data sources with your Salesforce platform. It's all about making informed decisions and gaining a competitive edge!…
Experience the Most Flexible, Easiest, and Securest Way to Integrate Salesforce and Jira
Integrate standard and custom Salesforce objects with Jira to strengthen cross-functional collaboration and deliver a top-notch customer experience. Fast-Track Your Journey to Attaining Customer Centricity…
Difference between Profile and Roles in Salesforce
Learn about the difference between Profile and Roles? Watch this video and do let us know if you have any questions or concerns.
Popular Salesforce Infographics
![Salesforce & Blockchain - Driving Businesses at the Speed of Trust](https://images.forcetalks.com/wp-content/uploads/2018/04/25081452/Salesforce-Blockchain-Driving-Businesses-at-the-Speed-of-Trust.png)
Salesforce & Blockchain : Driving Businesses at the Speed of Trust
Knowing the disrupter and the thought leader mind, Marc Benioff always has a way of looking at things with a beginners mind. With this thinking…
![salesforce productivity](https://images.forcetalks.com/wp-content/uploads/2018/01/20145646/salesforce-productivity.png)
A Better Way To Manage Your Salesforce | An Infographic
New software allows sales executives to see exactly where and how sales reps spend their time. These improved analytics give management a solid basis for…
![Salesforce Outsourcing](https://images.forcetalks.com/wp-content/uploads/2021/05/25185526/Salesforce-Outsourcing.jpg)
How Salesforce Outsourcing Can Help Your Business Grow
We all know how beneficial is Salesforce for any business but people still wonder if it is beneficial to go for Salesforce Outsourcing services. This…