Skip to main content
2 of 2
added 290 characters in body
BlackCat
  • 802
  • 6
  • 13

I have tested your code and it works in Lightning Experience (LEX) from VF page. The only thing, which doesn't work - when I click on button it initiates downloading csv file named download.csv in Chrome or randomly generated name in Firefox (not mydata.csv as you specified in JS).

Reason why it doesn't works in LEX? In the Salesforce app and Lightning Experience, Visualforce runs inside an iframe that’s inside the larger /lightning container. I guess because of that browsers ignore name specified in download attribute.

Also, I have tried your code directly in JS of lightning component/app. And, everything works as expected.

As a workaround, you can create for LEX separate button. And here you have three options:

  1. You can create lightning app with the same JS code on button click. User should be redirected to your lightning app /c/YourAppName.app instead of VF page.
  2. You can create lightning component which implements force:lightningQuickAction with the same JS code on button click. No redirects is required for this solution.
  3. You can create lightning component which implements force:appHostable,flexipage:availableForAllPageTypes with the same JS code on button click. User should be redirected to your lightning tab /lightning/n/YourTabName instead of VF page.
BlackCat
  • 802
  • 6
  • 13