0

I am trying to convert the Salesforce Classic Javascript button to Lightning Experience. The button has a custom URL. I don't know how to replace the custom URL in lightning. The button uses the connection query and some alert as well.

Please let me know how to convert the Javascript button to Lightning Experience.

Below is the Javascript button code:

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 
var result = sforce.connection.query("Select id,Name,Geocoding_Status__c from Account where id = '{!Account.Id}'");
var accountRecords = result.getArray("records");
var arrayLength = accountRecords.length;
if(arrayLength>0){
    for(var i=0;i<arrayLength;i++){
        if(accountRecords[i].Geocoding_Status__c=='OK'){
            var r = confirm('This will retrieve data from our data partner, Core Logic. Press OK to confirm.');
            if(r==true){
                var LeinCheck = sforce.apex.execute('LeinCheckCoreLogicIntegration','CoreLogicCallout',{id:'{!Account.Id}',conID:'{!Contact.Id}'});
                sforce.debug.trace = true;
                location.reload(true);
            }else{

            }
        }else{
            alert('Please correct the Account address for this Contact. Lien Check requires a valid address.');
        }
    }
}

Thank You

0

Use the standard converter: HERE

If that doesn't work, you should create a lightning component that does the same functionality --> Seems like a query for a single account record and a callout using an apex method. You can later expose your lightning component as a button and voila! Good luck!

| improve this answer | |
  • I have started writing the lightning component for the JS button. I have called the @AuraEnabled method which is returning me the query result. But in JS button I have to check the "accountRecords[i].Geocoding_Status__c=='OK'" . But in helper, I am not able to check that. – Naman Jain Aug 14 '19 at 15:47
  • You should be able to check in the js controller, js helper and the apex controller for that condition. What issue are you seeing? Can you post the code here for further inspection? – Glen De Marcos Aug 14 '19 at 16:55
  • Now I reached till if condition Geocoding_Status__c=='OK'. But don't know how to convert confirm in lightning controller or helper. Do you have any idea how to replace confirm(). – Naman Jain Aug 14 '19 at 19:12
  • The easiest way is to add the confirm to the onclick of the command button. The action will only execute if they select "OK". biswajeetsamal.com/blog/add-a-confirm-dialog-to-a-command-button/ – Glen De Marcos Aug 14 '19 at 19:22
  • But the link shows for VF page <apex:commandButton reRender="frm" value="Remove" action="{!remove}" onclick="if(!confirm('Do you want to remove?')){return false};" title="Remove"/>. But how to do in lightning controller or helper – Naman Jain Aug 14 '19 at 19:27

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.