-
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
What are Field Dependencies in Salesforce in 2023? | All You Need to Know
Salesforce is a powerful CRM platform that allows businesses to customize and tailor the software to their specific needs. One of the ways this is…
Understanding sObjects in Salesforce: A Comprehensive Guide
Introduction In the realm of Salesforce, sObjects play a crucial role in managing and manipulating data. Short for "Salesforce Objects," sObjects are the fundamental data…
Steps to Install the Salesforce Force.com IDE Plug-In in Eclipse
Force.com IDE can be installed into your existing Eclipse distribution. Following are the prerequisite to install Force.com IDE on your workstation : Don’t forget to check…
Popular Salesforce Videos
Salesforce Billing - Digital Wallets and Alternative Payment Methods
THE GOAL: In this video, you will learn how to use Alternative Payment Methods and Digital Wallets with Salesforce Billing. BEFORE YOU BEGIN, KNOW THE…
Use Case Hierarchy to Link Cases in Salesforce
Want to link your cases, so you and your team have a complete view of what’s going on with a customer? Do you want to…
Future of Salesforce Job Market | The Shrey Sharma Show
This is the very first episode of The Shrey Sharma Show with Christopher A Hopper. They discussed Salesforce. Below is a list of questions they…
Popular Salesforce Infographics
Unlock Agile and Efficient Salesforce Testing With AI-Driven Tools
Like every industry, the world of software testing and quality assurance has also gone under massive development with the emergence of AI technology. Developers and…
Why Integrate Your Pardot Account with Salesforce?
Salesforce Sales Cloud is primarily a sales tool while Pardot is a marketing automation platform. Both are designed to increase sales and maximize efficiency for…
Different Salesforce Marketing Cloud Products
Salesforce Marketing Cloud offers a number of products and solutions for customer journey management, advertising, social, email, mobile, content creation, web personalization, and data analysis.…