-
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
System Mode and User Mode in Salesforce
System mode implies running apex code by overlooking the user's authorizations. User mode understands the running apex code by concerning the user’s support and sharing…
In-house vs. Offshore Salesforce Developers: Who to Choose in 2021?
CRM systems are prevalent in most organizations, particularly those that deal directly with customers. To be exact, 91% of companies with the size of at…
Expertise and Support: The Key Benefits of Choosing a Salesforce Partner Company - InfoDrive Solutions
Salesforce is a powerful platform that can help businesses streamline their operations, increase productivity, and improve customer relationships. However, implementing and managing Salesforce can be…
Popular Salesforce Videos
Which Certification Is Needed In Salesforce for Getting Job?
Want to get a job in the Salesforce industry? Wondering which certifications are going to help. Join this useful group for Salesforce job & career…
Salesforce Billing and Cryptocurrency
THE GOAL: In this video, you're going to learn how Cryptocurrencies can work with Salesforce Billing. ☝️ BEFORE YOU BEGIN, KNOW THIS: 1. In terms…
Salesforce Connections 2018 Keynote - Ch. 1: Corporate Positioning
Salesforce Connections 2018 Keynote – Ch. 1: Corporate Positioning Salesforce Connections 2018 Keynote – Ch. 2: Ticketmaster Is A Trailblazer Salesforce Connections 2018 Keynote –…
Popular Salesforce Infographics
Why Salesforce End-user Training Matters for Smooth Implementation
This infographic 'Why Salesforce end-user training matters for smooth implementation' appeared first on Cynoteck. The progress of any CRM implementation depends on its general adoption…
7 Key Factors to Keep in Mind When Selecting Salesforce CPQ Software
Today, sales teams are increasingly overwhelmed with complex product offerings and customers’ expectations to deliver quick and personalized experiences. That’s why, sales professionals are inclining…
Success With Salesforce For Full Cycle Reps
Not only are you out prospecting for new leads like and SDR, you have to turn around and work those deals to close like an…