-
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
Salesforce Customer 360 Innovations - Path to success
Enterprises are looking for solutions to improve their business operational efficiencies while facing challenging marketing situations such as logistics disruption, inflation, and workforce shortage. So,…
How Integrating Salesforce with Accounting Tools Helps Businesses to Change the Operational Paradigm
In a world where work from home has become the new normal, businesses quickly need to adapt to the changing market scenario. Companies must take…
Fast Track your Marketing Activities and Enhance User Experience with DemandBlue's Salesforce Marketing Cloud Accelerators
Salesforce Marketing Cloud is one of the most used digital marketing platforms. DemandBlue’s set of Marketing Cloud and Pardot accelerators are uniquely backed by a decade of…
Popular Salesforce Videos
Introduction to Salesforce CPQ | EP1
Session 1: Introduction to Salesforce CPQ: The video provides an introduction to the general quoting challenge many Customers face, and how Salesforce CPQ with its…
Dynamic Action in Salesforce | Salesforce Tutorial
In this video, we are going to talk all about dynamic actions in Salesforce. 00:00 Introduction 00:57 Work with Dynamic Action 05:05 Dynamic Actions in…
How to Create a Connected App in Salesforce? | What is a Connected App?
Watch this video to learn how to create a Salesforce connected app to enables an external application to integrate with Salesforce using APIs. If you…
Popular Salesforce Infographics
How to Choose the Right CRM for Your Business?
There are many CRM solutions for companies to choose from, and wading through the wide range of options can seem like a daunting task. Choosing…
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 Marketing Cloud
Salesforce Marketing Cloud is a platform where relevant and personalized journeys are delivered across different devices and channels. This allows the marketers to deliver right…