-
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
How to Display Images from File Tab to Salesforce App by using Aura Component?
What are Aura Components? Aura components are a type of user interface framework used in Salesforce. They are built using the Aura framework, which is…
How to Use Salesforce to Improve Your Automobile Business?
The automobile industry is complex and ever-changing. In order to stay ahead of the competition, automobile businesses need to use the latest technology to improve…
Apex Trigger In Salesforce - Get Started
The trigger is an apex code that executes before and after the DML operations. Following are the DML operations:- Insert Update Delete Upsert Merge Undelete…
Popular Salesforce Videos
How to Focus on Report Results in Salesforce Console | Salesforce
When you work with reports in a fast-paced Salesforce Console environment, every extra click or focus change can slow you down. Now a streamlined console…
Salesforce Mobile Publisher Demo
With Salesforce Mobile Publisher, you can create pixel-perfect mobile applications for employees, customers, and partners. Check out this video and learn all you need to…
Automate Simple Business Processes with Process Builder | Salesforce Trailhead
In this video, we working on the Trailhead challenge Lightning Flow unit Automate Simple Business Processes with Process Builder where a lot of trailblazers face…
Popular Salesforce Infographics
Business Transformation With Salesforce AppExchange
Salesforce AppExchange acts as a comprehensive resource for Salesforce users, offering a vast collection of solutions tailored to various departments, industries, and business use cases.…
How Building Apps on Salesforce Has Tremendous ROI
The pressure that businesses today are under to reduce costs, improve agility, and deliver better results is no joke. Couple that with rapidly evolving technology…
How to Navigate a Successful Salesforce Implementation
There are many ways to navigate a Salesforce implementation. Check out this infographic to learn how to do it successfully.