Skip to content

Instantly share code, notes, and snippets.

@kevanmoothien
Created December 1, 2018 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevanmoothien/2aea0ff042bcc0c15f85b0b9a73b2e74 to your computer and use it in GitHub Desktop.
Save kevanmoothien/2aea0ff042bcc0c15f85b0b9a73b2e74 to your computer and use it in GitHub Desktop.

Apex Controller

public class CasePriority {
    @RemoteAction
    public static list<Case> getCases(string priority) {
        list<Case> cases = [Select Id, CaseNumber, Subject, Description, Priority, Status 
                              From Case 
                              Where Priority = :priority
                              And Status = 'New'
                           	  Limit 5];
        if (cases.isEmpty()){
            return new list<Case>();
        }
        return cases;
    }
}

Visualforce Page

<apex:page controller="CasePriority" lightningStylesheets="true">
    <script type="text/javascript">
    function getCases(priority) {
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.CasePriority.getCases}', priority,
            function(result, event){
                if(event.status){
                    var html = '<table>';
                    html += '<tr><th>Case Number</th><th>Subject</th><th>Priority</th></tr>';
                    result.forEach(function(item){
                        html += '<tr>';
                        html += '<td>'+ item.CaseNumber +'</td>';
                        html += '<td>'+ item.Subject +'</td>';
                        html += '<td>'+ item.Priority +'</td>';
                        html += '</tr>';
                    })
                    html += '</table>';
                    document.getElementById('results').innerHTML = html;
                }           
            },
            {escape: true}
        );
    }
    </script>
    
    <apex:pageblock id="block">
        <apex:pageblockbuttons location="top" >
            <apex:form>
            	<apex:commandButton value="High" onclick="getCases('High'); return false;" />
                <apex:commandButton value="Medium" onclick="getCases('Medium'); return false;"/>
                <apex:commandButton value="Low" onclick="getCases('Low'); return false;"/>
            </apex:form>
            
        </apex:pageblockbuttons>
        
        <apex:pageblocksection columns="1" id="blockSection">
            <div id="results">
                
            </div>
        </apex:pageblocksection>
    </apex:pageblock>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment