-
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
5 Benefits of Salesforce for Insurance
When it comes to insurance CRM, Salesforce enjoys massive popularity, and deservedly so. Salesforce goes beyond the typical CRM functionalities and offers out-of-the-box capabilities. It…
Using the runAs Method in Salesforce | Apex Developer Guide
By and large, all Apex code runs in framework mode, where the authorizations and record sharing of the current client are not considered. The framework…
Leverage Salesforce Integration Services to Retain Valuable Customers
We all have heard that integrating Salesforce with other applications provides organizations much greater operational visibility and access to unknown resources. It offers innovative products…
Popular Salesforce Videos
How to Delete Preloaded Sample Data in New Salesforce Organizations
When Users begin a trial or subscription with Salesforce, their org comes with a set of sample data. This data includes Accounts, Contacts, and Opportunities.…
Google Home Assistant Integration with Salesforce
Check out the below link for pdf view. https://www.linkedin.com/pulse/google-home-assistant-integration-salesforce-rajkiran-dewara/
Einstein For Marketing Cloud | The Learning Guide
AI has made things easy and smooth for any automation process. Einstein for Marketing Cloud provides insights and data to inform the content and timing…
Popular Salesforce Infographics
Sneak Peek: Latest Features And Updates of Salesforce commerce Cloud
Here is an infographic of the Latest Features And Updates of Salesforce commerce Cloud
10 Common Salesforce Mistakes—and How to Avoid Them
Salesforce integration is challenging if you don’t know exactly what you’re getting into. It’s an enormously valuable project, but diving into it without proper understanding…
A Four-step Formula for Salesforce Implementation
No matter how big or small your company—or the Salesforce CRM project—success requires planning, commitment, and strong sponsorship from your company’s executive team. It’s also…