Activity Forums Salesforce® Discussions Access Custom Controller-Defined Enum in Salesforce Custom Component?

  • shariq

    Member
    September 22, 2018 at 9:48 pm

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

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos