-
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

Learn All About the Batch Apex in 2023
The main purpose of using Batch Apex is used to process a large amount of data without exceeding governor limits. It is a type of…

Custom Lookup Field in Visualforce Page | Salesforce Developer Guide
We all know about the Standard Lookup functionality, it's provided by Salesforce. The standard Lookup field gives a dialog box that supports a little quantity…

Mastering Salesforce Marketing Cloud Email Studio: Step-by-Step Guide
The area of digital marketing is dominating nowadays, and customer engagement determines the success of any business. So, Salesforce Email Studio Marketing is the right…
Popular Salesforce Videos
How to Find the Job ID for a Test Send and Send Flow | Salesforce
This video will help you understand how to find the job id for a Send Flow and for a Test Send. 00:00 - Introduction 00:30…
Salesforce Data Management - Data Loader - Insert, Update, Upsert, Export, Delete
Use the Data Loader wizards to add, modify, or delete records. The upsert wizard combines inserting and updating a record. If a record in your…
Introduction to Salesforce Flow Builder
Watch this video to learn about Salesforce Flow Builder. 0:00 Introduction 2:50 Introduction to Salesforce Flows 4:40 Types of flows, Screen, Auto-Launched 7:10 Components related…
Popular Salesforce Infographics

How to Select Best Salesforce Implementation Partner
Selecting a Salesforce Implementation Partner may be both challenging and straightforward at the same time, particularly if this is your first time searching for a…

10 MUST HAVE Qualities Your Salesforce Administrator Should Have
Does your organization have a Salesforce Admin? If you use Salesforce or are in the process of implementing it, the role of Salesforce Admin is…

Build On Your Salesforce Service Cloud With Cognitive Search
Employees waste around 20% of their time looking for information to do their job. That’s a lot, isn’t it? This means there is one giant…