+ Start a Discussion

List View Button - How to display errors & confirmation on the list view?

I have a list view button that lets you select records and it does stuff with the selected records.

However, I can't find any info on how to NOT navigate to a new page after clicking the button. 


My ideal solution is:

1) Click button

2) Controller determines the conformation or error message

3) Add confirmation or error message to the List view


So far I have a crappy workaround with the VF page showing the error + a back link:



<apex:page standardController="Replacer__c" recordSetVar="r" extensions="replacerRunAllSelectedRulesController" action="{!runSelectedRules}">
    <apex:pagemessages />
    <A HREF="javascript&colon;javascript&colon;history.go(-1)">Back to previous page</A>


The relevent parts of my controller:


public with sharing class replacerRunAllSelectedRulesController{

    ApexPages.StandardSetController setCon;
    private PageReference savePage;

    public replacerRunAllSelectedRulesController(ApexPages.StandardController controller) {
        //Not sure why this is needed...

    public replacerRunAllSelectedRulesController(ApexPages.StandardSetController controller) {
        List<Replacer__c> selectedRules=new List<Replacer__c>();
    public PageReference runSelectedRules(){
        List<Replacer__c> selectedRules=new List<Replacer__c>();
        for(sObject s: setCon.getSelected()){
            Replacer__c r=(Replacer__c)s;
        }//for 1
        String objectName='';
        Boolean sendEmail=TRUE;
        	ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 
        	'You must select at least one rule.  Please go back and select a rule by checking the checkbox and try again.'));        
	        Integer numJobsCantBeRunNow=replacerExecute.replacerQueueBatchJobs(objectName, selectedRules, sendEmail);
	            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM,'Replacement has begun.  This can take ~10-30 minutes for each 10,000 records.  You will receive 1 email confirmation for each different object as all rules for one object are run together in one job.');
	            //else throw an error that they need to select fewer rules to run right now
	            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'The selected rules cannot be run now as they would exceed your companies batch job limit of 5.  One job is created for each different object.  Please unselect ' + numJobsCantBeRunNow + ' object\'s rules and try again.  To view the batch queue, click Setup-->Monitoring-->Apex Jobs'));
	        }//if 2
        }//if 1
        return ApexPages.CurrentPage();






If the SFDC solution is too complicated, does anyone have a javascript solution that works here?