I'm trying to show an alert in a Visualforce (custom listview button) if the controller receives less than 1 or more than 99 id's. The VF get's the integer from the apex controller once a listview button is clicked. I thinks the problem is not the controller but the VF script, that is probably not allowed in a VF button and is not being called anywhere.

The Visualforce page (listview button):

<apex:page standardController="CustomLead__c" recordSetVar="leads" action="{!validateAndRedirect}" extensions="ButtonEnergyLeadDigitalSendController" lightningStyleSheets="true">

    function checkSelected(){
        let selected = '{!selectedRecords}'
            alert('No ha seleccionado ningún lead para su reproceso');
        }else if(selected>99){
            alert('Por favor, seleccione un número de leads inferior a 100');


The apex controller:

public Class ButtonEnergyLeadDigitalSendController {

    public Integer selectedRecords {get {return getMySelectedSize();} }
    public List<id> energyleadIds;
    public ApexPages.StandardSetController setCon;

    public ButtonEnergyLeadDigitalSendController(ApexPages.StandardSetController controller) {
        setCon = controller;

    public Integer getMySelectedSize() {
        System.debug('setCon.getSelected().size(): '+setCon.getSelected().size());
        return setCon.getSelected().size();

    public void envioagencias(){

        energyleadIds = new List<id>();

        for(sObject eLeadDig : setCon.getSelected()){

        List <sObject> listaObj;
        listaObj = [SELECT ... FROM CustomLead__c WHERE id IN: energyleadIds];


    public PageReference validateAndRedirect(){

        Listview idListview = [SELECT Id, Name, DeveloperName FROM ListView WHERE SObjectType = 'GPMIR_obj_energyLead__c' and DeveloperName = 'Lead_de_Energ_a_Area_Digital'];
        PageReference retURL = new PageReference('/a33?fcf='+ idListview.Id);

        if(selectedRecords>0 && selectedRecords<100){

        return retURL;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.