• Will_M
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have a VF page (code below) that has a custom button which grabs the value of a field and give a download popup for saving to a file that value. This works smoothly in visualforce. In Classic, it looks something like this https://sfuser-dev-developer-edition.na50.force.com/apex/Weather_View?id=a0A6A000009XV2k&sfdc.override=1 However, once we migrated to Lightning, the button gives a weird popup (attached screenshot) and the download file and format is changed (filename becomes just download and it does not identify the format that was provided). Is there a way I can fix this issue? We are not migrating to Lightning components anytime soon so we'll have to live with this VF page being rendered in Lightning for a while.
I tried to tweak the href attribute in the JS but it doesn't look that helped.

Lightning Experience error image
 
<apex:page standardController="Weather__c" showHeader="false" sidebar="false">
    <apex:pageMessages />
    <apex:form>
        <apex:pageBlock mode="maindetail" title="Weather Details">
            <apex:pageBlockSection columns="2">
                <apex:outputField value="{!Weather__c.Name}" />
                <apex:outputField value="{!Weather__c.OwnerId}" />
                <apex:outputField value="{!Weather__c.City__c}" />
                <apex:outputField value="{!Weather__c.TempInFahrenheit__c }" />
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="forecastid" value="Forecast Details"/>
                    <apex:outputField id="forecastid" value="{!Weather__c.Forecast_Details__c }"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputPanel style="padding-left: 45%">
                        <apex:commandButton value="Download Forecast Details" oncomplete="downloadVal('Forecast_Details' + '.txt', 'false')" />
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

    <script type="text/javascript">
        function downloadVal(filename, addText) {
            var data = '{!Weather__c.Forecast_Details__c}';
            var bundleData = data;
            try {
                if(addText == 'true') {
                    newText = 'Adding some more text';
                    bundleData = data + '\n' + newText;
                }
                var element = document.createElement('a');
                element.setAttribute('href', 'data:application/text;charset=utf-8,' + encodeURIComponent(bundleData));
                element.setAttribute('download', filename);
                element.style.display = 'none';
                document.body.appendChild(element);
                element.click();
                document.body.removeChild(element);
            } catch(e) {
                alert(e);
            }
        }
    </script>
</apex:page>

 
  • January 17, 2019
  • Like
  • 1
I have a VF page (code below) that has a custom button which grabs the value of a field and give a download popup for saving to a file that value. This works smoothly in visualforce. In Classic, it looks something like this https://sfuser-dev-developer-edition.na50.force.com/apex/Weather_View?id=a0A6A000009XV2k&sfdc.override=1 However, once we migrated to Lightning, the button gives a weird popup (attached screenshot) and the download file and format is changed (filename becomes just download and it does not identify the format that was provided). Is there a way I can fix this issue? We are not migrating to Lightning components anytime soon so we'll have to live with this VF page being rendered in Lightning for a while.
I tried to tweak the href attribute in the JS but it doesn't look that helped.

Lightning Experience error image
 
<apex:page standardController="Weather__c" showHeader="false" sidebar="false">
    <apex:pageMessages />
    <apex:form>
        <apex:pageBlock mode="maindetail" title="Weather Details">
            <apex:pageBlockSection columns="2">
                <apex:outputField value="{!Weather__c.Name}" />
                <apex:outputField value="{!Weather__c.OwnerId}" />
                <apex:outputField value="{!Weather__c.City__c}" />
                <apex:outputField value="{!Weather__c.TempInFahrenheit__c }" />
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="forecastid" value="Forecast Details"/>
                    <apex:outputField id="forecastid" value="{!Weather__c.Forecast_Details__c }"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputPanel style="padding-left: 45%">
                        <apex:commandButton value="Download Forecast Details" oncomplete="downloadVal('Forecast_Details' + '.txt', 'false')" />
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

    <script type="text/javascript">
        function downloadVal(filename, addText) {
            var data = '{!Weather__c.Forecast_Details__c}';
            var bundleData = data;
            try {
                if(addText == 'true') {
                    newText = 'Adding some more text';
                    bundleData = data + '\n' + newText;
                }
                var element = document.createElement('a');
                element.setAttribute('href', 'data:application/text;charset=utf-8,' + encodeURIComponent(bundleData));
                element.setAttribute('download', filename);
                element.style.display = 'none';
                document.body.appendChild(element);
                element.click();
                document.body.removeChild(element);
            } catch(e) {
                alert(e);
            }
        }
    </script>
</apex:page>

 
  • January 17, 2019
  • Like
  • 1
I have a lightning component that I'm putting on a Community page, and I want to place a download link on it - to download an attachment.

In Visualforce - I always did...
<apex:image value="/servlet/servlet.FileDownload?file={!attachmentId}"  />Download</apex:image>

So, in the markup of the component, I've tried
<a href="{!'/servlet/servlet.FileDownload?file=00P4D000000Oub6'}">Download</a>

But when I do this, and click on the link - it just's takes me to a Site is in Maintenance message. 

Has anybody done a download link of an attachment ID in a componet?

Thanks