-
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 Make Your Fundraising Campaigns More Effective Through Salesforce
Salesforce has earned its place as one of the most intuitive and comprehensive CRM solutions in the market today that’s been used by many businesses.…
Salesforce Product : Financial Services Cloud
The world's #1 CRM Salesforce has something great for financial services which is Financial Services Cloud. Financial Services Cloud enables the feature to connect entire organization…
Salesforce Marketing Cloud
What is Marketing Cloud? To manage the relationship between marketers and customers, we use Marketing Cloud. Salesforce Marketing Cloud is used to make a interaction…
Popular Salesforce Videos
Sharing Rules in Salesforce
Use sharing rules to extend sharing access to users in public groups, roles, or territories. Sharing rules allow administrators to automatically bypass organization-wide sharing settings.…
Salesforce Object Query Language (SOQL) Crash Course | The Complete Hands-on Tutorials
SOQL in Salesforce is used to retrieve data from the Salesforce database for specific information. This video covers everything you need to know as a…
Developer Life in India | An Interview with Salesforce Chef
Timecode: 00:00 Introduction 01:10 Who is Amit Singh? 01:56 Amit has interesting projects 03:58 Amit does technical content, but he is still popular. How? 05:45…
Popular Salesforce Infographics
New Pardot Features: What was delivered in Summer ’18
New Pardot features, summer '18. Pardot has treated us to many enhancements across the core tool and related products. This infographic gives you an overview…
Enjoy the Salesforce Innovation Management infographic
Without innovation, a company will stay in one place. Without getting ideas from those closest to your product or service - customers, employees, and partners…
CRM BENEFITS FOR SMALL BUSINESS
As small businesses become more established, business owners should start considering customer relationship management (CRM) systems that are both affordable and effective. In this infographic,…