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
Frank CarterFrank Carter 

Lightning: custom button on related list

Hello,
I need help. I have a Javascript button on related list of a custom object and I want to bring this button on Lightning (always on related list).
The Javascript code makes a query to delete all record with certain features.
I know that Javascript button aren't supported in Lightning. I tried created a vf page with standard controller on Custom_Object__c but I'm not able to see the vf paage on dropdown Content.
User-added image
is my approach wrong?

Thanks,
Frank
Best Answer chosen by Frank Carter
Khan AnasKhan Anas (Salesforce Developers) 
Hi Frank,

To be able to add Visualforce page in a 'List Button' you must have 'Standard List Controller' for the object on which list button needs to be visible.

Please refer to below document for adding Custom List Buttons using Standard List Controllers:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm?search_text=list%20button

I hope it helps you.

Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas


 

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Frank,

To be able to add Visualforce page in a 'List Button' you must have 'Standard List Controller' for the object on which list button needs to be visible.

Please refer to below document for adding Custom List Buttons using Standard List Controllers:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm?search_text=list%20button

I hope it helps you.

Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas


 
This was selected as the best answer
Frank CarterFrank Carter
I think it's correct, I share the code of my vf page:
<apex:page  standard Controller="Billing_Detail__c" recordSetVar="Billingdetails" >

<script type = "text/javascript">

//Javascript code
<script>
    
</apex:page>

it's not working. I don't see  the vf page on dropdown Content.
what am I doing wrong?

Thanks,
Frank
Khan AnasKhan Anas (Salesforce Developers) 
Hi Frank,

I checked in my org, it is working fine. If possible, please share your code.


Thanks,
Khan Anas
Frank CarterFrank Carter
At the moment I don't have any code because I don't see the button on related list. If I see the buttton then I'll try to add the code inside the tag script. This object, Billing_Detail__c is related to opportunity. I have the related list billing details on opportunity. On this related list (on classic) I have the javascript button. So to have the same function on Lightning I created a new list button on Billing Detail object with content source Visualforce page. I created this vf page :
<apex:page  standard Controller="Billing_Detail__c" recordSetVar="Billingdetails" >

<script type = "text/javascript">

//Javascript code
<script>
    
</apex:page>
but the problem is this :
User-added image
I don't see any vf page.
Frank CarterFrank Carter
If you want I can add the javascript code of the button that works on classic
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 
var result = sforce.connection.query("Select Id From Billing_Detail__c Where Billing_Detail__c= '{!Opportunity.Id}' AND Billing_Status__c!='Billed' AND Billing_Type__c!='FEE' AND Billing_Type__c!='PPU'"); 

var records = result.getArray("records"); 
var idsForDeletion = []; 

for (var i=0; i<records.length; i++) { 
idsForDeletion.push(records[i].Id); 
} 

sforce.connection.deleteIds(idsForDeletion); 
window.location.reload();

but I think is the next step.
Thanks,
FranK 
Frank CarterFrank Carter
I don't know why but now I view the vf page
Frank CarterFrank Carter
the problem is I don't see the button on lightning. I added on page layout.
User-added image

Can you help me?

thanks, Frank
Luan SantosLuan Santos

Frank, did you see the button already? If not.. Try mark the option in visualforce 'Available for lightning...'

This works for me.