You need to sign in to do that
Don't have an account?
Padma 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;
}
}
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;
}
}
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:
Controller:
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
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 :