• #36916
    Salesforce | Aman Aman #4
    Forcetalks

    Access Custom Controller-Defined Enum in Salesforce Custom Component?

    Access Custom Controller-Defined Enum in Salesforce Custom Component?

     

    #36917
    Salesforce | shariq shariq #1
    Forcetalks

    We cannot reference the enum directly since the enum itself is not visible to the page and you can’t make it a property.

    Example:

    Apex class:

    global with sharing class My_Controller {
    public Case currCase {get; set; }
    public enum StatusValue {RED, YELLOW, GREEN}

    public StatusValues getColorStatus() {
    return StatusValue.RED; //demo code – just return red
    }
    }

    Visualforce page:

    <apex:image url=’stopsign.png’ rendered=”{!colorStatus == StatusValue.RED}” />
    Above code snippet will throw error something like “Save Error: Unknown property ‘My_Controller.statusValue’”

    Resolution:
    Add below method in Apex Controller:

    public String currentStatusValue { get{ return getColorStatus().name(); }}
    and change Visualforce code to

    <apex:image url=’stopsign.png’ rendered=”{!currentStatusValue == ‘RED’}” />

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?