+ Start a Discussion

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

<apex:smileytongue:age controller="enerNOCController" tabStyle="Opportunity">
<apex:sectionHeader title="New Customer Opportunity"
subtitle="Step 1 of 2"/>

<apex:includescript value="{!$Resource.pageBlockSupplement}" />
    <apex:form >
        <apex:smileytongue:ageBlock title="My Content">
           <apex:smileytongue:ageBlockButtons >
                <apex:commandButton action="{!step2}" value="Next" styleClass="btn"/>
            <apex:smileytongue:ageBlockSection title="My Content Section" columns="2">
                <apex:inputField id="accountName" value="{!opportunity.AccountId}"/>




I also have a controller that holds some of the logic.  What I am thinking is I can use if(account.State=="New York":smileywink: 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?



return Page.opportunitydecisiontree2;
public PageReference save() {
insert opportunity;
PageReference opptyPage = new PageReference('/' +
return opptyPage;




Can anyone help me with this?



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?

Hi chriseustace;
If you want to show or hide an InputField according to the billingState you can do it as below.
If this is not what you want please try to supply more info.

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}"/>