function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Padma NeelaPadma Neela 

How to get record Ids from listview selected records through custom button click

I have default list view i created one custom button called generate COA when click I getting all recored insted of selected. What is wrong in my code. 
VFP :  <apex:page standardController="FinishedGoods__c" extensions="GenerateCOA"
            recordSetVar="conferences">
<apex:stylesheet value="{!$Resource.pdfStyle}"/>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!conferences}" var="c" border="2"   id="theTable"   >
        
            <apex:column value="{!c.Name}"  />
            <apex:column value="{!c.Lot_Number__c}"  />
          <apex:column value="{!c.Product_Name__c}"  />
             <apex:column value="{!c.Release_Date__c}"  />
            <apex:column value="{!c.Specifications__c}" />
            <apex:column value="{!c.Comments__c}" />
            <apex:column value="{!c.Product_Line__c}" />
            <apex:column value="{!c.Is_it_Rush__c}" />
           <apex:column value="{!c.Submitted_By__c}" />
             <apex:column value="{!c.Date_Received__c}"  />
       <apex:column value="{!c.Code__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
    
</apex:page>

Controler :
public class GenerateCOA {
 private ApexPages.StandardSetController standardSetController;
  public List<FinishedGoods__c> memList {get;set;}
   private Set<Id> memIds = new Set<Id>();
    public GenerateCOA(ApexPages.StandardSetController standardSetController)
    {
        this.standardSetController = standardSetController;
        
       
        memList = new List<FinishedGoods__c>();
        for (FinishedGoods__c mem : (List<FinishedGoods__c>)standardSetController.getSelected()){ 
             system.debug('mem.Id--->'+mem.Id); 
            memIds.add(mem.Id);
        }
        memList = [SELECT Id, Date_Received__c, Lot_Number__c, Product_Name__c, Release_Date__c, Comments__c, Product_Line__c, Is_it_Rush__c, Submitted_By__c, Specifications__c, Code__c, Name FROM FinishedGoods__c WHERE ID IN: memIds];
    }
    
    
 
    public PageReference doSomething()
    {
        // Apex code for handling records from a List View goes here
       // Id recordId = standardSetController.getId();
      //  system.debug('recordId'+recordId);
        List<FinishedGoods__c> selectedListViewRecords =
            (List<FinishedGoods__c>) standardSetController.getSelected();
        system.debug('Selected record id--->'+selectedListViewRecords[0].Id);
                return null;
    }
}


User-added image
Khan AnasKhan Anas (Salesforce Developers) 
Hi Padma,

Greetings to you!

Below is the sample code to get selected record ids of listview which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Account" recordSetVar="accounts" extensions="ListViewIdC">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!accounts}" var="a" >
            <apex:column value="{!a.Id}"/>
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Controller:
public class ListViewIdC {
    
    public List<Account> obj{get;set;}
    
    public ListViewIdC(ApexPages.StandardSetController controller) {
        obj = (List<Account>) controller.getSelected();
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Padma NeelaPadma Neela
Hi Khan Ana , 
Thanks for your time and trying help me, My case is custom object I tried same on Account object it is work but not with custom object , here is the screen shot. 

public class GenerateCOA {

  public List<FinishedGoods__c> memList {get;set;}

    public GenerateCOA(ApexPages.StandardSetController standardSetController)
    {
           memList = (List<FinishedGoods__c>) standardSetController.getSelected();
        system.debug('mem.Id--->'+memList.size()); 
      }
    
}

<apex:page standardController="FinishedGoods__c" extensions="GenerateCOA"
            recordSetVar="conferences">

<apex:stylesheet value="{!$Resource.pdfStyle}"/>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!conferences}" var="c" border="2"   id="theTable"   >
        
            <apex:column value="{!c.Name}"  />
            <apex:column value="{!c.Lot_Number__c}"  />
          <apex:column value="{!c.Product_Name__c}"  />
             <apex:column value="{!c.Release_Date__c}"  />
            <apex:column value="{!c.Specifications__c}" />
            <apex:column value="{!c.Comments__c}" />
            <apex:column value="{!c.Product_Line__c}" />
            <apex:column value="{!c.Is_it_Rush__c}" />
           <apex:column value="{!c.Submitted_By__c}" />
           
            <apex:column value="{!c.Date_Received__c}"  />
            
             
               
            <apex:column value="{!c.Code__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
    
</apex:page>

Here are the screen shots : 
User-added image