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

newbie to Apex - trying to display different info based on values
Hello all,
I am trying to develop a few visual force pages that based upon the Account State, I will redirect to different pages.
I have a basic page that allows the user to select an Account from a lookup
<apexage
controller="enerNOCController" tabStyle="Opportunity">
<apex:sectionHeader
title="New Customer Opportunity"
subtitle="Step 1 of 2"/>
<apex:includescript
value="{!$Resource.pageBlockSupplement}" />
<apex:form
>
<apexageBlock title="My
Content">
<apexageBlockButtons >
<apex:commandButton action="{!step2}" value="Next"
styleClass="btn"/>
</apexageBlockButtons>
<apexageBlockSection title="My
Content Section" columns="2">
<apex:inputField
id="accountName" value="{!opportunity.AccountId}"/>
</apexageBlockSection>
</apexageBlock>
</apex:form>
</apexage>
I
also have a controller that holds some of the logic. What I am
thinking is I can use if(account.State=="New York" then I'll do something
public
class enerNOCController {
Opportunity opportunity;
Account
account;
public Account getAcctName()
{
return [select
Name from Account limit 1];
}
public Account getAccount() {
if(account
== null) account = new Account();
return account;
}
public
Opportunity getOpportunity() {
if(opportunity == null) opportunity =
new Opportunity();
return opportunity;
}
public PageReference
step1() {
return Page.OpportunityDecisionTree;
}
public
PageReference step2() {
//use account.State?
if(account.State){
return
Page.opportunitydecisiontree2;
}
}
public PageReference save()
{
insert opportunity;
PageReference opptyPage = new
PageReference('/' +
opportunity.id);
opptyPage.setRedirect(true);
return
opptyPage;
}
}
Can anyone help me with this?
Thanks!
Hello chriseustace;
You there is no field named "State" in Account table. You need to use BillingState or ShippingState instead.
In your post it is not clear which is the account that you need to consider.
However you can do something as below.
public PageReference step2() {
Account acc = [SELECT id, BillingState FROM Account LIMIT 1]; //BillingState should be queried here
if(acc.BillingState == 'New York'){
return Page.opportunitydecisiontree2;
} else {
return null;
}
}
Awesome! I'll give that a shot in the AM. Appreciate the advice.
I know my logic wasn't fully drawn out, I was just trying to get pointed in teh right direction :)
One other question: Using Visual Force pages, is it possible to show/hide fields based upon critieria? Would it make more sense to embed that login in the page, or in the class?
public Boolean getIsRendered() {
Account acc = [SELECT id, BillingState FROM Account LIMIT 1];
if(acc.BillingState == 'New York'){
return true;
} else {
return false;
}
}
<apex:inputfield rendered="{!isRendered}"/>