You need to sign in to do that
Don't have an account?
basha sk
Here in visualforce page i have two selectoption dropdownlists.
Account list
Contacts list
In accounts list i'm displaing all salesforce accounts and based on the selected account I'm displaying the related contacts in Contacts list.
After getting the selected contact i'm mapping that contact details to the other custom object.
Req: How to filter the selected contact record from selectedOption list?
This is my apex class:
public with sharing class Picklist{
public String selectedAccId{get;set;}
public String selectedConId{get;set;}
public String selectedContactId{get;set;}
public String firstname;
public String lastname;
public String email;
public String company;
public String mailingcity;
public String mailingstate;
public String mailingcountry;
public String mobileno;
public Status__c login1;
List<System.SelectOption> conOptions{get;set;}
List<System.SelectOption> options{get;set;}
public Picklist(ApexPages.StandardController controller){
this.login1= (Status__c)controller.getRecord();
}
public List<System.SelectOption> accOptions{get;set;}
//getting all salesforce accounts
public List<System.SelectOption> getAccountNames(){
List<System.SelectOption> accOptions= new List<System.SelectOption>();
accOptions.add( new System.SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account] ){
accOptions.add( new System.SelectOption(String.valueOf(acc.Id),acc.name));
} return accOptions;
} //displaying all related contacts based the selectd account record. public List<System.SelectOption> getContactNames(){
List<System.SelectOption> conOptions= new List<System.SelectOption>();
if(selectedAccId != null){
for(contact con : [select Id,name,accountid,FirstName,LastName,email,MobilePhone,MailingCity,MailingState,MailingCountry from contact where accountid=:selectedAccId ]){
conOptions.add(new System.SelectOption(String.valueOf(con.Id),con.name));
System.debug('conOptions:::'+conOptions);
}
}
return conOptions;
}
//how to get the contact record from conatcs list.
public Pagereference getSelectedContact(){
System.debug('Entered Selected contact id...........'+selectedConId );
List<System.SelectOption> options = new List<System.SelectOption>();
if(conOptions.size() > 0){
System.debug('SelectId::::'+selectedConId);
for(Contact con1 : [select Id, name, Account.Name, accountid, FirstName, LastName, email, MobilePhone, MailingCity, MailingState, MailingCountry from contact where id=:selectedConId]){
firstname = con1.FirstName;
System.debug('Entered ContactNames contact id...........'+firstname);
lastname= con1.LastName; System.debug('lastname:::'+lastname);
email = con1.Email;
System.debug('email:::'+email );
}
}
else{ conOptions.add( new System.SelectOption('--None--','--None--')); } return null; } }
Thanks in advancce if anybody having idea please let me know
How to get selected value from selectOption values dropdown list
Here in visualforce page i have two selectoption dropdownlists.
Account list
Contacts list
In accounts list i'm displaing all salesforce accounts and based on the selected account I'm displaying the related contacts in Contacts list.
After getting the selected contact i'm mapping that contact details to the other custom object.
Req: How to filter the selected contact record from selectedOption list?
This is my apex class:
public with sharing class Picklist{
public String selectedAccId{get;set;}
public String selectedConId{get;set;}
public String selectedContactId{get;set;}
public String firstname;
public String lastname;
public String email;
public String company;
public String mailingcity;
public String mailingstate;
public String mailingcountry;
public String mobileno;
public Status__c login1;
List<System.SelectOption> conOptions{get;set;}
List<System.SelectOption> options{get;set;}
public Picklist(ApexPages.StandardController controller){
this.login1= (Status__c)controller.getRecord();
}
public List<System.SelectOption> accOptions{get;set;}
//getting all salesforce accounts
public List<System.SelectOption> getAccountNames(){
List<System.SelectOption> accOptions= new List<System.SelectOption>();
accOptions.add( new System.SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account] ){
accOptions.add( new System.SelectOption(String.valueOf(acc.Id),acc.name));
} return accOptions;
} //displaying all related contacts based the selectd account record. public List<System.SelectOption> getContactNames(){
List<System.SelectOption> conOptions= new List<System.SelectOption>();
if(selectedAccId != null){
for(contact con : [select Id,name,accountid,FirstName,LastName,email,MobilePhone,MailingCity,MailingState,MailingCountry from contact where accountid=:selectedAccId ]){
conOptions.add(new System.SelectOption(String.valueOf(con.Id),con.name));
System.debug('conOptions:::'+conOptions);
}
}
return conOptions;
}
//how to get the contact record from conatcs list.
public Pagereference getSelectedContact(){
System.debug('Entered Selected contact id...........'+selectedConId );
List<System.SelectOption> options = new List<System.SelectOption>();
if(conOptions.size() > 0){
System.debug('SelectId::::'+selectedConId);
for(Contact con1 : [select Id, name, Account.Name, accountid, FirstName, LastName, email, MobilePhone, MailingCity, MailingState, MailingCountry from contact where id=:selectedConId]){
firstname = con1.FirstName;
System.debug('Entered ContactNames contact id...........'+firstname);
lastname= con1.LastName; System.debug('lastname:::'+lastname);
email = con1.Email;
System.debug('email:::'+email );
}
}
else{ conOptions.add( new System.SelectOption('--None--','--None--')); } return null; } }
Thanks in advancce if anybody having idea please let me know
I believe once a Contact is selected in the picklist you will have the Record Id of the selected Contact captured in the selectedContactId property from my code snippet above.
Use the below code to identify the Contact record and map its values to another object's fields. Refer the code below with the additional methods to filter the selected Contact record based on the selection within the Contact picklist. Addition to this code are the getSelectedContact() and populateContactDetails() methods.
All Answers
you need to use :apex:selectList value=
Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com
Keep a tab on the number of results returned and hence the below code only retrieves 500 most recent Accounts and their associated Contacts.
I believe once a Contact is selected in the picklist you will have the Record Id of the selected Contact captured in the selectedContactId property from my code snippet above.
Use the below code to identify the Contact record and map its values to another object's fields. Refer the code below with the additional methods to filter the selected Contact record based on the selection within the Contact picklist. Addition to this code are the getSelectedContact() and populateContactDetails() methods.
Error: Compile Error: Method does not exist or incorrect signature: void containsKey(Id) from the type Set<Id> at line 53 column 40
at this line
public void getContactsByAccountId(Id pAccountId){
this.conOptions.add(new System.SelectOption('' , '--Select--'));
if(accountIdRecordMap.keySet().containsKey(pAccountId)){ //error at this line
vf page :
<apex:page standardController="Webinar_Attendees_Status__c" extensions="Picklist">
<apex:form>
<apex:pageBlock title="Registration Form">
Account Names
<apex:selectList value="{!selectedAccId}" size="1">
<apex:selectOptions value="{!accOptions}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
<br/><br/>
Related Contacts
<apex:selectList value="{!pAccountId}" size="1" id="a">
<apex:selectOptions value="{!conOptions}" />
</apex:selectList><br/>
<apex:pageBlockSection >
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks
Once done, update your <apex:page> to include an action call to invoke the getAccountsWithContacts() as shown below.
<apex:actionFunction name="DoFilter" action="{!getContactsByAccountId}" rerender="out" status="loading">
<apex:param assignTo="{!conOptions}" value="" name="Contacts List"/>
</apex:actionFunction>
I got some errors please check it once
Thanks
<apex:actionFunction name="DoFilter" action="{!getContactsByAccountId}" rerender="out" status="loading">
<apex:param assignTo="{!conOptions}" value="" name="Contacts List"/>
</apex:actionFunction>
Thanks