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
RIteshMRIteshM 

can we get the items selected on current page in List view

i am building a custom button for a list view and using java script described in this tutorial  http://www.interactiveties.com/b_execute_javascript_button.php .there is a doubt  related to this

 

1. we can get the list of selected items using  

 

{!GETRECORDIDS($ObjectType.Lead)};

if there is a pagination on list view. can we get the items selected on current page for example when we select A then it shows sobjects with name attributes started with A if we select some items from current page and we want to perform some operation on items selected on this page only .Is there any method for getting access to these records ?? please guideline



Ashish_SFDCAshish_SFDC

Hi RIteshM,

 

Please see the below links which may help,

http://salesforceblogger.blogspot.in/2012/03/sort-alphabetically.html

http://stackoverflow.com/questions/9357785/how-do-i-get-a-list-of-fields-in-alphabetical-order-in-sf

 

Regards,

Ashish, Salesforce.com

If this post answers your question, please mark this post as Solved.

Yash ShuklaYash Shukla
There are 2 ways to get it done:

1. Create a List Button and have a java script executed for the same using the syntax {!GETRECORDIDS($ObjectType.Lead)}; but this is restricted to the Classic mode of Salesforce as Java script buttons do not go well with the lightning mode of salesforce.
2. For Lightning Create a List Button->Select the Check Box to Allow Multiple Values->Create a VF page and align it with the button->Include a lightning component within the vf page and pass the values from the Vf Page to the Lightning Component attributes.


VF PAGE :

<apex:page standardController="Account" recordSetVar="accs" extensions="VFC_ProcessAccRecords">
<apex:includeLightning />
   
    <div id="LcDisplayId"></div> 
    
 <script>
      // Here 'VfApp' Is Lightning Application Name
    $Lightning.use("c:VfApp", function() {
      /* 'LcForVf' is Lightning Component Name which we are Displaying In Vf Page 
       * syntax for create lightning component dynamically :
       * $Lightning.createComponent(String type, Object attributes, String locator, function callback) */
    $Lightning.createComponent("c:LcForVf",
    { 
      // Set Lightning Component Attributes Property before creating Lightning Component In Visualforce page 
        textColor : "Red",
        currentUserName : '{!$User.FirstName} {!$User.LastName}' 
     },
   "LcDisplayId",
    function(component) {
        // create component Callback, Lightning Component has been Created,
        // Now you can set more lightning Component attributes here,
        // and do more cool stuff here
        component.set("v.accId" , '{!accs}');// the attribute to pass all the selected record ids 
    });
 });
 </script>
</apex:page>


////////////////////////

LC:

<aura:component >
  <!--declare aura attributes-->    
    <aura:attribute name="accId" type="string"/>
    <aura:attribute name="textColor" type="string" default="black"/>
    <aura:attribute name="currentUserName" type="string"/>
    
    <h2 style="{!'color:' + v.textColor}"> RecordId Pass With Vf Page URL Parameter : <b>{!v.accId}</b></h2>
     
    <br/>
    
    <p><span class="slds-badge">LogIn User :<b>{!v.currentUserName}</b></span></p>
   
    <br/>
    
    <button class="slds-button slds-button_brand" onclick="{!c.showAlert}">Show Alert</button>
</aura:component>

CONTROLLER
({
   showAlert : function(component, event, helper) {
     alert('Test Alert'+component.get('v.accId'));
       
    }
})


//////////////

APEX CLASS TO SET THE VALUES ON THE VF PAGE 

public class VFC_ProcessAccRecords {
    public List<Account> selAccLst;
    public String accIds{get;set;}
    public string msg{get;set;}
    
    // Constructor
    public VFC_ProcessAccRecords(ApexPages.StandardSetController cntlr){
        selAccLst = cntlr.getSelected(); //get selected records from account list view
        accIds = '';  
        for(Account acc : selAccLst){
            accIds += acc.Id + ','; //build list of ids string concatenated with comma                         
        }
        accIds = accIds.removeEnd(','); 
        system.debug('test '+accIds);
   } 
    
  
}