0

Hi I have requirement of producing a list in home layout with number is records available in different conditions and on pressing a button redirecting to the specific list view I came up with the following logic its working with displaying but, when a button clicked instead taking to particular listview it's just clear the table data and the button action method is getting called at all. I'm new to Salesforce could someone please review the following suggest something solve the problem.

Controller:

public class CarerDashboardListViewController{
    public static List<ListWrapper> lstwrapper {get; set;}
    public static List<ListCRNInfo> listCRNInfo {get; set;}
    public static List<ListDHHSInfo> listDHHSInfo {get; set;}
    public static List<ListHealthInfo> listHealthInfo {get; set;}
    public static String listItem {get; set;}
    public static Integer appsDhhs {get; set;}
    public static Integer appExternal {get; set;}
    public static Integer APPCOUNTCRN = 0;
    public static Integer APPCOUNTDHSS = 0;
    public static Integer APPCOUNTHEALTH = 0;
    public static String listName {get; set;}
    public Id crnListView {get; private set;}
    public Id dhhsListView {get; private set;}
    public Id heathListView {get; private set;}
    private static List<Application__c> appsToCRN;
    private static List<Application__c> appsToDHHS;
    private static List<Application__c> appsToHeath;

    private static final Id carerApplId = RecordTypeUtil.getRecordTypeIdFor('Application__c', 'Carer Card');
    //different list of details needed
    //List<Application__c> appsReadyForCRN = new List<Application__c>();
    //List<Application__c> appsCRNDone = new List<Application__c>();
    //List<Application__c> appsHeathProf = new List<Application__c>();
    List<Application__c> appsToList = new List<Application__c>();

    public CarerDashboardListViewController(){
        lstwrapper = new List<ListWrapper>();
        listCRNInfo = new List<ListCRNInfo>();
        listDHHSInfo = new List<ListDHHSInfo>();
        listHealthInfo = new List<ListHealthInfo>();
        appsToDHHS = new List<Application__c>();
        appsToCRN = new List<Application__c>();
        appsToHeath = new List<Application__c>();

        List<ListView> listIdCrn = [SELECT Id, Name FROM ListView 
                WHERE SObjectType = 'Application__c' AND Name = 'Carer Card - DHHS-CRN Check Pending'];
        if(listIdCrn.size() == 1) {
            this.crnListView = listIdCrn.get(0).Id;
        }

        List<ListView> listIdDhhs = [SELECT Id, Name FROM ListView 
                WHERE SObjectType = 'Application__c' AND Name = 'Carer Card - DHHS-Vendor Check Pending'];
        if(listIdDhhs.size() == 1) {
            this.dhhsListView = listIdDhhs.get(0).Id;
        }

        List<ListView> listIdHealth = [SELECT Id, Name FROM ListView 
                WHERE SObjectType = 'Application__c' AND Name = 'Carer Card - DHHS-CRN Check Pending'];
        if(listIdHealth.size() == 1) {
            this.heathListView = listIdHealth.get(0).Id;
        }

        initGetListDetails();
    }

    //button to define redirect
    public void buttonRedirect(){
        System.debug('"Method invoked' + listName);
        if(listName == 'openCrnApps'){
            openCrnApps();
        } else if(listName == 'openDHHSApps'){
            openDHHSApps();
        } else if(listName == 'openHealthCheckApps'){
            openHealthCheckApps();
        }
    }
    //get URL for all the listViews
    public PageReference openCrnApps(){
        System.debug('CRN is invoked');
        Schema.DescribeSObjectResult r = Schema.getGlobalDescribe().get('Application__c').getDescribe();
        String url = '/'+r.getKeyPrefix()+'?fcf=' + this.crnListView;
        url = url.substring(0, url.length() - 3);
        return new PageReference(url);
    }

    public PageReference openDHHSApps(){
        System.debug('DHHS Call');
        Schema.DescribeSObjectResult r = Schema.getGlobalDescribe().get('Application__c').getDescribe();
        String url = '/'+r.getKeyPrefix()+'?fcf=' + this.dhhsListView;
        url = url.substring(0, url.length() - 3);
        return new PageReference(url);
    }

    public PageReference openHealthCheckApps(){
        Schema.DescribeSObjectResult r = Schema.getGlobalDescribe().get('Application__c').getDescribe();
        String url = '/'+r.getKeyPrefix()+'?fcf=' + this.heathListView;
        url = url.substring(0, url.length() - 3);
        return new PageReference(url);
    }

    public void initGetListDetails(){
        //getting apps
        //appsToList = [SELECT Id, Status__c, Sub_Status__c FROM Application__c WHERE Status__c = 'Processing' AND (Sub_Status__c = 'DHHS - Vendor Check Pending' OR Sub_Status__c = 'DHHS - CRN Check Pending' OR Sub_Status__c = 'Health Professional Pending')];
        appsToCRN = [SELECT Id, Status__c, Sub_Status__c FROM Application__c WHERE Status__c = 'Processing' AND Sub_Status__c = 'DHHS - CRN Check Pending' AND RecordTypeId = :carerApplId];
        appsToDHHS = [SELECT Id, Status__c, Sub_Status__c FROM Application__c WHERE Status__c = 'Processing' AND Sub_Status__c = 'DHHS - Vendor Check Pending' AND RecordTypeId = :carerApplId];
        appsToHeath = [SELECT Id, Status__c, Sub_Status__c FROM Application__c WHERE Status__c = 'Processing' AND Sub_Status__c = 'Health Professional Pending' AND RecordTypeId = :carerApplId];

        System.debug('CRN'+appsToCRN.size());
        System.debug('DHHS'+appsToDHHS.size());
        System.debug('HEALTH'+appsToHeath.size());

        if(!appsToCRN.isEmpty()){
            listCRNInfo.add(new ListCRNInfo(appsToCRN));
        }

        if(!appsToDHHS.isEmpty()){
            listDHHSInfo.add(new ListDHHSInfo(appsToDHHS));
        }

        if(!appsToHeath.isEmpty()){
            listHealthInfo.add(new ListHealthInfo(appsToHeath));
        }

    }

    public class ListCRNInfo{

        public ListCRNInfo(List<Application__c> apps){
            lstwrapper.add(new ListWrapper('No. of applications ready for CRN check',String.valueOf(apps.size()),'openCrnApps'));
        }
    }

    public class ListDHHSInfo{

        public ListDHHSInfo(List<Application__c> apps){
            lstwrapper.add(new ListWrapper('No. of applications ready for DHHS vendor check',String.valueOf(apps.size()),'openDHHSApps'));
        }
    }

    public class ListHealthInfo{

        public ListHealthInfo(List<Application__c> apps){
            lstwrapper.add(new ListWrapper('No. of applications ready for health Professional check',String.valueOf(apps.size()),'openHealthCheckApps'));
        }
    }

    public class ListWrapper{
        public String listItem {get; private set;}
        public String appsPending {get; private set;}
        //public String appsProcessed {get; private set;}
        public String buttonRedirect {get; private set;}

        public ListWrapper(String listName, String numberOfApps, String buttonValue){
            this.listItem = listName;
            this.appsPending = numberOfApps;
            this.buttonRedirect = buttonValue;
        }
    }
}

Visualforce:

<apex:page controller="CarerDashboardListViewController" title="Snapshot of Applications">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!lstwrapper}" var="item" title = "Snapshot of Applications">
                <apex:column headerValue="List View Name">
                    <apex:outputLabel value="{!item.listItem}" />
                </apex:column>
                <apex:column headerValue="Number Of Records">
                    <apex:outputLabel value="{!item.appsPending}" />
                </apex:column>
                <apex:column headerValue=" ">
                    <apex:commandButton action="{!buttonRedirect}" value="check">
                    <apex:param name="a" value="{!item.buttonRedirect}" assignTo="{!listName}"/></apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

I had to get the value of appropriate value of button dynamically from the page that's why came up with parameterised button action.

0

You're never returning your PageReference to the Visualforce runtime, so the redirect that you're expecting to happen does not take place. Instead, the page reloads, having the effect of blanking out your work. Here's why that's happening:

Your <apex:commandButton>

<apex:commandButton action="{!buttonRedirect}" value="check">

calls buttonRedirect(), which calls through to your dispatch methods:

public void buttonRedirect(){
    System.debug('"Method invoked' + listName);
    if(listName == 'openCrnApps'){
        openCrnApps();
    } else if(listName == 'openDHHSApps'){
        openDHHSApps();
    } else if(listName == 'openHealthCheckApps'){
        openHealthCheckApps();
    }
}

such as openCrnApps(), which does construct and return a new PageReference for the location that you want to end up in.

//get URL for all the listViews
public PageReference openCrnApps(){
    // ... snipped ...
    return new PageReference(url);
}

But here's the problem: that PageReference goes nowhere, because buttonRedirect() returns void, and throws away the return value from openCrnApps() and friends.

Easy fix: change

public void buttonRedirect(){

to

public PageReference buttonRedirect(){

and everywhere you call a dispatch method, add a return:

    if(listName == 'openCrnApps'){
        return openCrnApps();
    } // etc.
  • Hi David, I'm still getting the same problem even after changing the method. – Mohammed Imran Oct 29 '18 at 0:41
  • Mohammed, could you edit a detailed description into your question? Can you use debug logs to identify exactly which lines of code are executed when you click the button, and describe what the page behavior is after you've made this change? – David Reed Oct 29 '18 at 13:33
  • Hi David, Thanks for your time I have changed the whole setup. just added the link to wrapper class as string and access it as hyperlink in visualforce and that worked. – Mohammed Imran Oct 30 '18 at 5:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.