I am trying to create a custom 'take ownership' for Case list view in Lightning.

I took the classic Javascript button (from @sfdcfox answer to this question - Custom button on list view), and included that in a VisualForce Page as follows:

<apex:page standardController="Case" recordSetVar="Case">
<apex:includeScript value="/soap/ajax/31.0/connection.js"/>
<apex:includeScript value="/soap/ajax/29.0/apex.js"/>
<apex:includeScript value="/support/console/26.0/integration.js"/>
<apex:includeScript value="/support/console/26.0/integration.js"/>
    var caseIds = {!GETRECORDIDS($ObjectType.Case)};
    var cases = [], tempCase, result;
    while(caseIds.length) {
    tempCase = new sforce.SObject('Case');
    tempCase.Id = caseIds.shift();
    tempCase.OwnerId = '{!$User.Id}';
    result = sforce.connection.update(cases);
    window.top.location.href = window.top.location.href;

After selecting few cases from List view, and using the custom button, there's an exception - 'getRecordIds is not defined' :

enter image description here

  • Mentioning a user in a question doesn't notify a user, but I felt my metaphorical ears burning. Go ahead and give it a try. – sfdcfox Jul 29 '17 at 0:16
  • Thank you sfdcfox, I knew this will catch you attention and highly professional hands :) I just need to struggle the test class now, to complete this. – iDog Jul 29 '17 at 7:47

JavaScript buttons don't work the way you expect, and I'm pretty sure that the code you're trying to use won't work. That said, you have an alternative you can use (tested/verified).

First, create a new Apex Class:

public class CaseAcceptOwnership {
    PageReference cancel;
    Case[] records;
    public CaseAcceptOwnership(ApexPages.StandardSetController c) {
        records = (Case[])c.getSelected();
        cancel = c.cancel();
    public PageReference updateCases() {
        for(Case record: records) {
            record.OwnerId = UserInfo.getUserId();
        update records;
        return cancel.setRedirect(true);

Next, create a Visualforce page:

<apex:page standardController="Case" recordSetVar="cases" extensions="CaseAcceptOwnership" action="{!updateCases}">

After that, go to Setup > Customize > Cases > Buttons, Links, and Actions, and create a new List Button (with select checkboxes), choose Visualforce for the Content Source, and choose the new page you created.

Finally, go ahead and add this button to your Search Layout, and you're done. The user can select records, and when they click the button, they will own the selected cases. You may want to add some error handling or something, but this should get you started.

| improve this answer | |

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.