You need to sign in to do that
Don't have an account?

combine picklist values from two different objects for vf page
Hi, I am trying to combine two picklist values from two different objects for selection on my vf page.
let's say, I have an object opportunity with Stage picklist
there is another object as "Order Intake" which is the child of opportunity; it has a picklist which says if the oif days are due by options:
10 days
20 days
30 days
I am creating a picklist for vf page as 'Select category' where I want options as Stage values + Order Intake values;
when I select the options it should display respective Order Intake or opportunity.
Please assist
let's say, I have an object opportunity with Stage picklist
there is another object as "Order Intake" which is the child of opportunity; it has a picklist which says if the oif days are due by options:
10 days
20 days
30 days
I am creating a picklist for vf page as 'Select category' where I want options as Stage values + Order Intake values;
when I select the options it should display respective Order Intake or opportunity.
Please assist
All Answers
the resolution you provided above worked.. I just needed to twist it a bit to fit it to my requirement as below
for( Schema.PicklistEntry OppickListVal : Opple){
options.add(new selectoption(OppickListVal.getValue(), OppickListVal.getLabel()));}
for(Schema.PicklistEntry ObjpickListVal : Objple){
options.add(new selectoption(ObjpickListVal.getValue(), ObjpickListVal.getLabel()));}
return options;
Thank you
Now I want to reflect records from these values based on selection from different the two objects.. any suggestion will be helpful.. below is my current code; its reading only for opportunity and not for vehicles.. thanks
public class Opportunitiesandvehicles{
public string selectedvalue{set;get;}
public boolean isclicked{set;get;}
public boolean flag{set;get;}
public list<opportunity> opplist {get;set;}
public boolean isBool{set;get;}
public list<vehicle__c> vehiclelist{get;set;}
public Opportunitiesandvehicles(){
isclicked = false;
isBool = false;
flag = false;
opplist = new List<Opportunity>();
getopvehPickValues();
}
public List<SelectOption> getopvehPickValues()
{
List<SelectOption> options = new List<SelectOption>();
/* Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('','--None--'));
for(Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
} */
Schema.DescribeFieldResult OppFldResult = Opportunity.Stagename.getDescribe();
List<Schema.PicklistEntry> Opple = OppFldResult.getPicklistValues();
Schema.DescribeFieldResult ObjFldResult = Vehicle__c.type__c.getDescribe();
List<Schema.PicklistEntry> Objple = ObjFldResult.getPicklistValues();
// list<selectoption> optionLst = new list<selectoption>();
options.add(new selectoption('', '-None-'));
for( Schema.PicklistEntry OppickListVal : Opple){
options.add(new selectoption(OppickListVal.getValue(), OppickListVal.getLabel()));}
for(Schema.PicklistEntry ObjpickListVal : Objple){
options.add(new selectoption(ObjpickListVal.getValue(), ObjpickListVal.getLabel()));}
return options;
}
public void searchopportunityRecords(){
system.debug('sfdc test');
if(selectedvalue == null || selectedvalue== ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please select value for opportunity or vehicles'));
isclicked = false;
isBool = false;
}
else{
system.debug('sfdc test1');
isclicked=true;
Opplist = [SELECT Id, Name, stagename FROM opportunity Where stagename=:selectedvalue];
system.debug('opplist = '+opplist.size());
}
if(opplist.size() == 0){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please pick a value from the piclist above'));
isclicked = false;
isBool = true;
}
}
public PageReference displayvehicles() {
if(selectedvalue!= null){
isclicked=true;
vehiclelist= [SELECT Id, Name, type__c from Vehicle__c Where type__c=:selectedvalue];
system.debug('opplist = '+vehiclelist.size());
}
if(vehiclelist.size() == 0){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please pick a value from the piclist above'));
isclicked = false;
isBool = true;
}
return null;
}
}
_____________________-
<apex:page controller="Opportunitiesandvehicles" id="pg" lightningStylesheets="true">
<style>
.mypage .quote {
margin: 12px 0;
font-size: 32px;
text-align: center;
}
</style>
<apex:form id="frm">
<apex:pageBlock title="Search Criteria" mode="edit">
<apex:pageBlockSection >
<apex:selectList size="1" style="width:10%;" value="{!selectedvalue}" styleClass="slds-input">
<apex:selectOptions value="{!opvehPickValues}" />
</apex:selectList>
<br/><br/>
<apex:commandButton value="Show" styleClass="slds-button slds-button_brand" action="{!searchopportunityRecords}"/>
</apex:pageBlockSection>
<apex:pageMessages id="showmsg"></apex:pageMessages>
</apex:pageBlock>
<apex:outputpanel rendered="{!isclicked==true}" >
<apex:pageBlock title="Search Result" mode="edit">
<apex:pageBlockTable value="{!opplist}" var="Items">
<apex:column headervalue="Opportunity Name">
<apex:inputField value="{!Items.Name}"/>
</apex:column>
<apex:column headervalue="Opportunity StageName">
<apex:inputfield value="{!Items.StageName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock mode="edit" >
<apex:pageBlockTable value="{!vehiclelist}" var="con" >
<apex:column headervalue="Vehicle Name">
<apex:inputfield value="{!con.Name}"/>
</apex:column>
<apex:column headervalue="Vehicle Type">
<apex:inputfield value="{!con.Type__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>