-
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,…
Things to Know About Salesforce Dreamforce 2019
Summer is over, and that can only mean one thing, Dreamforce is near. Dreamforce is the biggest annual conference held by Salesforce. There are so…
Automation studio in Marketing cloud
Automation Studio - Automation Studio makes Marketing Cloud email sends, queries, imports, and more happen automatically. Automation Studio is a Salesforce Marketing Cloud application used…
Popular Salesforce Videos
Salesforce Service Cloud Overview Demo
Service Cloud is a complete service solution built on the Salesforce platform that lets you quickly adapt to change, to deliver trusted service from anywhere.…
How To Create Permission Set Group | Salesforce Development Tutorial
How to create permission set groups. This video will cover the following points - 1. Introduction Get a brief introduction about Permission Set Groups. 2.…
Create an Email Alert Workflow Rule | Workflow Rules in Salesforce | Salesforce Automations
Configuring Workflow Rule Email Alerts or Notifications Follow. Workflow Rules are automatic processes that trigger an action when a certain event occurs, such as updating…
Popular Salesforce Infographics
Things you need to know about Salesforce Commerce Cloud
Salesforce Commerce Cloud a.k.a. Demandware is a highly customized, multi-tenant, and cloud-based Software as a Service (SaaS) eCommerce solution. It offers a wide range of…
Salesforce Einstein GPT For Technical Expertise
Did you know how Salesforce Einstein GPT provides technical capabilities? Explore the potential of Einstein GPT and how it could be beneficial for technical endeavors.…
Welcome to the Internet of Customers | Salesforce Infographic
You’ve heard this age-old adage a thousand times: “The customer is always right.” Today more than ever, the customer has countless technologies and practices in…