Showing posts with label base URL. Show all posts
Showing posts with label base URL. Show all posts

Thursday, February 6, 2020

How to download the files using URL from salesforce

Note: To download the file, require the Content Version record Ids

For Single File

Use the below URL to download the single file from the salesforce.
URL https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX

String idCntDoc = '068XXXXXXXXXXXX';
String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/' + idCntDoc;
System.debug('URL ===> '+strURL);

For Multiple Files

URL: https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX/068XXXXXXXXXXXX
above URL downloads the files in ZIP folder

list<String> lstCntVersionIds = new list<String>{'068XXXXXXXXXXXX', '068XXXXXXXXXXXX'};

String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/';

for(String iterator : lstCntVersionIds) {
    strURL += iterator + '/';
}

strURL = strURL.removeEnd('/');

System.debug('URL ===> '+strURL);

Sunday, January 5, 2020

How to get Salesforce Base URL in Lightning Web Component(lwc)

To get Salesforce base URL use the window.location object can be used to get the current page address (URL).
The window.location.origin property returns the origin URL of the current page.



Ex URL: https://lwcpractice1-dev-ed.lightning.force.com/lightning/r/Account/001B000000vZWOHIA4/view

HTML File
<template>
    <lightning-card title="Salesforce Base URL in Lighting Web Component">
        <div class="slds-text-heading_medium slds-text-align-center">
            SFDC Base URL : <p></p><lightning-formatted-url value={sfdcBaseURL} ></lightning-formatted-url></p>
        </div>
    </lightning-card>
</template>

JS File
import { LightningElement } from 'lwc';

export default class BaseURL extends LightningElement {
    sfdcBaseURL;

    renderedCallback() {
        this.sfdcBaseURL = window.location.origin;
    }
}

Output