You need to sign in to do that
Don't have an account?
SFDC12
vf scenario
Hi every my scenario is to display the opportunity picklist in dropdown based on the picklist we select related records should display and if we click on update ,it should update ihave tried so far ,able to display picklist values but unable to display the records,below is the code
Apex:
public class opp1 {
public List<SelectOption>options {set;get;}
public List<opportunity>opportunities {set;get;}
public List<oppwrapper>oppwraplist {set;get;}
public string selected {set;get;}
public opp1(){
options=new List<SelectOption>();
opportunities=new List<opportunity>();
oppwraplist=new List<oppwrapper>();
List<string>stagevalues=new List<string>{'prospecting','price/quote','need Analysis'};
for(string op:stagevalues){
SelectOption eachstage=new SelectOption(op,op);
options.add(eachstage);
}
}
public void updatestages(){
List<opportunity>opportunities=new List<opportunity>();
for(oppwrapper ow:oppwraplist){
if(ow.flag){
ow.opp.stageName='selected';
opportunities.add(ow.opp);
}
}
}
public class oppwrapper{
public opportunity opp {set;get;}
public boolean flag {set;get;}
}
}
vf:
<apex:page controller="opp1" >
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!options}">
</apex:selectOptions>
</apex:selectList>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!opportunities}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.stageName}"/>
<apex:column value="{!a.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:commandButton value="update" action="{!updatestages}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex:
public class opp1 {
public List<SelectOption>options {set;get;}
public List<opportunity>opportunities {set;get;}
public List<oppwrapper>oppwraplist {set;get;}
public string selected {set;get;}
public opp1(){
options=new List<SelectOption>();
opportunities=new List<opportunity>();
oppwraplist=new List<oppwrapper>();
List<string>stagevalues=new List<string>{'prospecting','price/quote','need Analysis'};
for(string op:stagevalues){
SelectOption eachstage=new SelectOption(op,op);
options.add(eachstage);
}
}
public void updatestages(){
List<opportunity>opportunities=new List<opportunity>();
for(oppwrapper ow:oppwraplist){
if(ow.flag){
ow.opp.stageName='selected';
opportunities.add(ow.opp);
}
}
}
public class oppwrapper{
public opportunity opp {set;get;}
public boolean flag {set;get;}
}
}
vf:
<apex:page controller="opp1" >
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!options}">
</apex:selectOptions>
</apex:selectList>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!opportunities}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.stageName}"/>
<apex:column value="{!a.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:commandButton value="update" action="{!updatestages}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Please try the below updated code:
VF Page:
Apex Class:
Thanks,
Maharajan.C
All Answers
Please try the below updated code:
VF Page:
Apex Class:
Thanks,
Maharajan.C
Thanks in Advance
@isTest
public class opo1Test {
@isTest
static void call(){
//sample data
opportunity o=new opportunity();
o.stageName='prospecting';
o.closeDate=system.today();
o.name='testopp';
insert o;
//call the class name
opp1 op=new opp1();
op.updatestages();
op.deleteoppt();
op.oppList();
opp1.oppwrapper ow=new opp1.oppwrapper();
ow.flag=false;
ow.opp.stageName='prospecting';
}
}