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"/>
<script>
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}';
cases.push(tempCase);
}
result = sforce.connection.update(cases);
window.top.location.href = window.top.location.href;
</script>
</apex:page>
After selecting few cases from List view, and using the custom button, there's an exception – 'getRecordIds is not defined' :
Best Answer
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:
Next, create a Visualforce page:
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.
Edit: Example Unit Test
Again, does not cover failure conditions, so make sure you add additional error handling if there's a possibility of failure.