0

I want to perform a specific operation on the records selected in a list view.The user can select any view and the functionality would remain the same.

Is there any way using which we can get the records selected in a list view?

Please help.

1
  • You could create a List Button and get the selected records from the user's selection. Is that what you mean?
    – sfdcfox
    Jun 8, 2017 at 15:12

1 Answer 1

0

You can't access list view using SOQL.We created a method which might help you see how we use List Views in APEX. Our Task was to get a LIST VIEW URL based on the LABEL (view name). You cannot retrieve ID's based on the LIst View API Name as the describe sobject only returns a ListOption which is a value and label. [Copied from here] All Accounts

Controller :

   public class listViewController 
   {
        Public AllAccountsListViewURL {get;set;}
        public listViewController ()
        {
            Map<String,String> PrefixList = PrefixList();   

           AllAccountsListViewURL = ListViewURL(PrefixList,'Account','All Accounts');
        }
        Public Map<String,String> PrefixList(){
           Map<String,String> PrefixList = new Map<String,String>{};
           Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
           for(String sObj : gd.keySet()){
               Schema.DescribeSObjectResult r =  gd.get(sObj).getDescribe();
               PrefixList.put(r.getName(), r.getKeyPrefix());
           }
           return PrefixList;
        } 
        Public String ListViewURL(Map<String,String> PrefixList,String ObjectName,String ListViewLabel)
        {
           String ListViewURL;
           String ListViewId;
           String q = 'SELECT Name FROM '+ ObjectName +' LIMIT 1';
           ApexPages.StandardSetController ACC = new ApexPages.StandardSetController(Database.getQueryLocator(q));
           List<SelectOption> ListViews = ACC.getListViewOptions();
           for(SelectOption w : ListViews ){
               if(w.getLabel()==ListViewLabel){
                   ListViewId = w.getValue().left(15);
                   ListViewURL='/'+PrefixList.get(ObjectName)+'?fcf='+ListViewId;
               }
           }
           return ListViewURL;
        }
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .