Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created May 1, 2019 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/c571fbdf06ccaa0e54edef10783f1c08 to your computer and use it in GitHub Desktop.
Save arun12209/c571fbdf06ccaa0e54edef10783f1c08 to your computer and use it in GitHub Desktop.
copyToClipboardCmpController
({
doInit : function(component, event, helper) {
//get the object details from apex
helper.getsObjectName(component,event,helper);
},
copyLink:function(component,event,helper){
//dynamically creating html component
var hiddenInputEle = document.createElement("input");
//get the title of clicked element (record link)
let val = event.getSource().get("v.title");
//set value attribute as actual record link
hiddenInputEle.setAttribute("value", val);
//append the element in the document body
document.body.appendChild(hiddenInputEle);
// select the content
hiddenInputEle.select();
// Execute the copy command
document.execCommand("copy");
document.body.removeChild(hiddenInputEle);
//Show toast message after link copied in the clipboard
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
mode: 'sticky',
title: 'Success!',
message: 'Link has been copied to clipboard.',
type: 'success'
});
toastEvent.fire();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment