-
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

Displaying data from the related Supplier__c records on a Visualforce page that has a custom controller for the Buyer__c object
How can a developer display data from the related Supplier__c records on a Visualforce page that has a custom controller for the Buyer__c object? The…

Building Apps Using Salesforce AppExchange
Introduction Salesforce AppExchange was launched in 2005. Salesforce AppExchange is an Online Store just like the 'Play store' in Android phones. It is the marketplace…

Triggers in Salesforce - Learn All You Need to Know
What is Apex Trigger? Apex Triggers are used to refer to triggers in Salesforce. These are different and are accessible for particular tasks such as…
Popular Salesforce Videos
Salesforce is a fancy database
In this video, We will learn about the Salesforce Database (Data Modelling) in-depth in an interesting and fun way. I have divided this video into…
Salesforce 101 for Salespeople
In this video, Oliver Sholder breaks down Salesforce 101 for us. He covers everything from what Salesforce is and does, to how it can benefit…
Salesforce CRM Services offered by Melonleaf Consulting
Melonleaf Consulting offers customized and configured Salesforce CRM Solutions and Services that can revolutionize your business. Experience the power of top-notch and highly effective Salesforce…
Popular Salesforce Infographics

Enhance Productivity with Salesforce Lightning
As a business professional, you are always looking for ways to increase productivity while keeping your team motivated and moving forward. Salesforce Lightning platform is…

Salesforce Jobs Market Couldn't Be Better!
Anyone that’s transitioned their career to Salesforce can agree: the market for Salesforce Jobs couldn’t be better. If you’re looking for some inspiration to make…

Benefits of Using WhatsApp For Better Customer Engagement
WhatsApp makes businesses more interactive and reliable. Customers can directly connect with a company, clear their doubts, and leverage a connected experience. 5 million business…