-
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
Is Your Salesforce Org Ready for Lightning Experience?
Almost a year ago Salesforce launched the biggest innovation, named Lightning. Lightning gave a completely new platform and user experience, and even day by day…
Quick Tips for Managing Multiple Marketing Cloud Instances
It requires art to manage multiple cloud instances, specifically when aiming to maintain efficient, consistent, and effective communication across different platforms. Marketing cloud platforms include…
Salesforce Financial Services Cloud | Empower your borrowers with Mortgage Innovation
Loans and Mortgages are key elements of today’s economy and there is a likelihood that every adult at some time or other has been part…
Popular Salesforce Videos
Dreamforce To You 2020 - Algoworks
The wait is over – Dreamforce will be going ahead in 2020! Salesforce has gone back to the drawing board and rebuilt Dreamforce 2020 for…
How I Really Feel About Salesforce
A deep dive into the state of the Salesforce industry in 2021, such as: - Is Salesforce going to crash in the foreseeable future? -…
Salesforce Development Tutorial - sObjects
It is very easy to learn Salesforce with the world class training tutorial. Training is key for the right knowledge. Those who work as an…
Popular Salesforce Infographics
Benefits of Salesforce Commerce Cloud
As the online marketplace is continuously growing in the global economy, it's important to have a feature-loaded and scalable e-commerce platform. Salesforce commerce cloud is…
How Salesforce Admins Manage their Data?
No matter how long you’ve been working within Salesforce, it’s important to regularly evaluate the data management systems you have in place and review the…
Salesforce Administrator Salaries – Around The World
A Salesforce administrator; the gatekeeper to an organisation’s Salesforce capabilities. With the huge acceleration of data in our lives, it’s no surprise that job roles…