You need to sign in to do that
Don't have an account?
Richard Valencia
Help with Javascript code for custom button in Lighting
I'm currently moving my team over to lighting and I'm needing help with converting a custom Java button that can not be converted by the Salesforce Converter tool.
My custom button lives in a Custom object and is placed on the Related list. The buttom currently allows users to make the checkbox = ture and and then select the "Complete" button(JS) which will then mark all the selected records as "Completed" this is currenlty working in Classic but not avliable in lighting.
Java code for classic button:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")};
var records1 = {!GETRECORDIDS($ObjectType.Milestone1_Task__c)};
var newRecords = [];
var taskRec = sforce.connection.query('select id,name,Task_Stage__c from Milestone1_Task__c where id in (\'' + records1.join('\',\'') + '\')' );
var tasks = taskRec.getArray("records");
var arrayLength = tasks.length;
if(records1==null || records1=='') {
alert('No records selected');
}
else{
for(var i=0;i<arrayLength;i++){
var tsk = new sforce.SObject("Milestone1_Task__c");
tsk.Id = tasks[i].Id;
tsk.Task_Stage__c = 'Completed';
newRecords.push(tsk);
}
result = sforce.connection.update(newRecords);
window.location.reload();
}
My custom button lives in a Custom object and is placed on the Related list. The buttom currently allows users to make the checkbox = ture and and then select the "Complete" button(JS) which will then mark all the selected records as "Completed" this is currenlty working in Classic but not avliable in lighting.
Java code for classic button:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")};
var records1 = {!GETRECORDIDS($ObjectType.Milestone1_Task__c)};
var newRecords = [];
var taskRec = sforce.connection.query('select id,name,Task_Stage__c from Milestone1_Task__c where id in (\'' + records1.join('\',\'') + '\')' );
var tasks = taskRec.getArray("records");
var arrayLength = tasks.length;
if(records1==null || records1=='') {
alert('No records selected');
}
else{
for(var i=0;i<arrayLength;i++){
var tsk = new sforce.SObject("Milestone1_Task__c");
tsk.Id = tasks[i].Id;
tsk.Task_Stage__c = 'Completed';
newRecords.push(tsk);
}
result = sforce.connection.update(newRecords);
window.location.reload();
}
I recommend reviewing this blog to get started
Also, Is the lightning experience configuration converter tool not detecting the javascript button?
Configuration Converter tool output: