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
Yogesh BiyaniYogesh Biyani 

Convert Javascript Button to Lightning Component (Step by Step instructions)

We have 3 Javascript buttons which change the record type and reassigns the case to a queue. Here is an example 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 
caseObj.RecordTypeId = '012400000009FQA';
caseObj.OwnerId = '00G40000001dp2s'

var result = sforce.connection.update([caseObj]);

if (result[0].success =='false') {
alert (result[0].errors.message);
} else {
location.reload(true);
}

I am looking for detailed step-by-step instructions/tutorial to convert this to Lightning Component. 

Thank you in advance. 
Shalini RShalini R
Hi Yogesh Biyani,

Please refer the below link. It will help you.

https://salesforce.stackexchange.com/questions/184836/help-to-convert-onclick-javascript-button-to-lightning

Regards,
Shalini R

 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Yogesh Biyani,

May I suggest you please refer the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
Yogesh BiyaniYogesh Biyani
Shalini, Rahul, Thank you for your help. Yogesh
Yogesh BiyaniYogesh Biyani
Hello Shalini,

As suggested in StackExchange I have created the following apex page but when I use the button the new page keeps on refreshing. What am I missing? 
<apex:page standardController="Case">
    <apex:includeScript value="../../soap/ajax/20.0/connection.js"/>
    <script>
    sforce.connection.sessionId='{!GETSESSIONID()}';
    var caseObj = new sforce.SObject("Case"); 
    caseObj.Id = '{!Case.Id}'; 
    caseObj.RecordTypeId = '012400000009FQA';
    caseObj.OwnerId = '00G40000001dp2s'
    
    var result = sforce.connection.update([caseObj]);
    
    if (result[0].success =='false') {
        alert (result[0].errors.message);
    } else {
        location.reload(true);
    }
    </script>
</apex:page>
User-added image

Thanks in advance for your help.

Yogesh
Shalini RShalini R
Hi Yogesh,

You have mentioned in the above coding like that location.reload(true) thats the reason page is reloading when update successful.
Please remove that line and mentioned some alert for success message.

Regards,
Shalini R
Yogesh BiyaniYogesh Biyani
Hello Shalini,

Thanks for the reply.  The flickering has stopped.  Is there a way to automatically close the window after it is done? 
Yogesh
 
Shalini RShalini R
Hi Yogesh,

Please use the below lines, you can able to close window and refresh cash record.

window.opener.location.href = "/{!Case.Id}";
window.self.close();
Somnath Paul 22Somnath Paul 22
Hi Yogesh, You can visit the below blog post to complete your requirement. You will get step by step instruction and they are using LC to replace JS button.
https://sompaul2012.wordpress.com/2018/04/05/lightning-action-as-a-replacement-of-javascript-button/
Alex GroagAlex Groag
Hi - I'm not a developer. We have some javacript buttons that need to created for lightning use. If i post the javascript can anyone send me the apex to convert it in lightning? Thanks
Dhanush RDhanush R
Hi,
Can anyone please help me convert the below javascript code to lightning.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

var processStatusValue = "{!Delegation__c.Process_Status__c}"; 

var delegation = new sforce.SObject("Delegation__c"); 


delegation.Id = "{!Delegation__c.Id}"; 




if(processStatusValue=="Requested"){ 

if(confirm("Are you Sure You Want To Cancel!") == true) 

delegation.Process_Status__c = "Cancelled"; 

//alert(delegation.Process_Status__c ); 

var result = sforce.connection.update([delegation]); 
//alert('result'+result); 

//alert('result'+result.errors.message); 

if(result[0].success == "true"){ 
location.reload();