1

I'm creating Lightning Component that displays Classic version of the Current URL record page with a button that onclick copy to the clipboard that URL.

Just a simple functionality that saves time for Lightning Users, when they need to send a URL of the record to non-Lightning users.

Cmp:

<lightning:button class="slds-align_right slds-button slds-button_neutral" iconName="utility:copy_to_clipboard" variant="border-filled" label="Copy" onclick="{! c.copyClassic }"/>
<textarea readonly="true" id="urlClassic">https://name.my.salesforce.com/{!v.recordId}</textarea>

Controller:

({
copyClassic : function(cmp, event){
  var urlClassic = document.getElementById('urlClassic');
  urlClassic.select();
    document.queryCommandSupported('copy');
    document.execCommand('copy');
    var source = event.getSource();
    source.set('v.label', 'COPIED!');
    setTimeout(function(){
        source.set('v.label', 'Copy');
    }, 2000);
} })

It is working on first copied page, but if I open in the same window new record, Textarea displays new URL (with the new record page) and button changed to 'COPIED!' but it's not selecting and copying new URL.

Does anyone has similar issue or idea to solve this problem?

0 Answers0