Salesforce Add Action To apex:EnhancedList

There’s no quick way to add actions to a Salesforce VisualForce page with an EnhancedList. Here’s the workaround.

apex:page >
    script type="text/javascript">    
    function endsWith(str, suffix) {
        return str.indexOf(suffix, str.length - suffix.length) !== -1;
    }
    function setActions() {        
        Ext.ComponentMgr.all.each( function(item, index, length) {
            if(endsWith(item.id, "grid")) {        
                var store = item.store;                    
                item.store.each( function(record) {
                    record.set("ACTION_COLUMN", ["My Action"]);
                });
            }
        });
    }
    /script>
    apex:enhancedList type="Systems__c" height="300" oncomplete="setActions();" />
/apex:page>

Salesforce uses the Extjs framework (Sencha.com) to implement list views. All user interface components on an Extjs page are registered with a component manager. The code accesses the component manager, looks for a component whose id corresponds to a grid (our EnhancedList), and then changes the action items in the store associated with the grid.

Leave a Reply

Your email address will not be published. Required fields are marked *