-
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
Generate More Leads With Salesforce's Data.com
Salesforce.com's Sales Cloud customer relationship management (CRM) software includes a sales and lead creation component called Data.com. Through its enormous user-generated database, the Data.com platform…
7 Salesforce Products that can Transform Your Business
Salesforce is a top-rated CRM that offers businesses a diverse range of products to enhance their business model and operations. With each Salesforce product specifically…
5 Best CRM Integrations with QuickBooks for SMBs 2022
It's crucial that your CRM and QuickBooks work together. Due to this, most CRMs on the marketplace have acted and offered a method to integrate…
Popular Salesforce Videos
How to Deliver Great Customer Service With a Small Team [Salesforce Webinar]
Overwhelmed by a backlog of customer service requests? And worried your team is too small to handle all the requests? Then, this video is for…
New Product: RepBlaze on Salesforce AppExchange
Visit on AppExchange: Click Here As a Sales manager, if you deal with 1000’s of inbound and other leads everyday and would love to automate…
Build Multi-Column Screens in Flow Builder - Spring'21 feature for the Salesforce Screen Flows
Build Multi-Column Screens in Flow Builder (Pilot) You can divide each flow screen into multiple sections and columns to create a visually appealing and effective…
Popular Salesforce Infographics
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…
Average Salesforce Salaries in 2023-2024: What You Need to Know
Salesforce is a popular CRM platform that is used by businesses of all sizes. If you're considering a career in Salesforce, you may be wondering…
How Salesforce Financial Service Cloud Enhance Insurance Services?
Salesforce Financial Services Cloud (FSC) is the #1 AI CRM tool that helps you achieve this goal. Its magical AI-powered services boost customer onboarding and retention and…