Inserting file in Salesforce file/attachment object Using custom REST API Uses property of “ContentVersion”, “ContentDocumentLink” and “getBodyAsBlob()” in apex class post method in Salesforce #3
Labels
documentation
Improvements or additions to documentation
In this post we are going to learn about How to call an external REST API to uploading files to SFDC file/attachment object using REST call in Salesforce Apex Post Methods.
This example we are uploading files to Salesforce object using custom REST API and property of ContentVersion, ContentDocumentLink and getBodyAsBlob() in Salesforce Apex Class Post Method.
To access the external REST API, First we need to Adding the Remote Site Settings
Setup ➡ Remote Site Settings ➡ Remote Site Name ➡ Enter the URL for the remote site
👉 Get source code live demo link:-
Create Lightning Component
Step 1:- Create Lightning Component : apiIntegrationCmp.cmp
`<aura:component controller="downloadExcelApiCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="oppObj" type="Opportunity" default="{'sobjectType' : 'Opportunity'}"/>
<aura:attribute name="oppMode" type="Map"/>
<aura:attribute name="oppName" type="String" default=""/>
<aura:attribute name="response" type="Map"/>
<aura:attribute name="spinnerImg" type="boolean" default="false"/>
<lightning:button variant="brand" label="Insert File in Salesforce" title="Insert File in Salesforce" type="Button" onclick="{!c.apiIntegrateAction}"></lightning:button>
</aura:component>`
Create Component JavaScript Controller
Step 2:- Create Lightning Component : apiIntegrationCmpController.js
From Developer Console ➡ File ➡ New ➡ Lightning Component ➡ JavaScript Controller
`({
apiIntegrateAction : function(component, event, helper) {
var recordId = component.get("v.recordId");
var oppName = component.get('v.oppName');
var action = component.get("c.fileInsert");
action.setParams({
"url": 'https://test.com/fileInsert',
"recId":recordId,
"oppNameStr": oppName,
"fileName": oppName,
});
action.setCallback(this, function(response){
var state = response.getState(response);
})`
Create Apex Class Controller
Step 3:- Create Apex Class : downloadExcelApiCtrl.apxc
`@RestResource(urlMapping='/insertFileToSalesforce/')
global class downloadExcelApiCtrl {
}`
👉 Get source code live demo link:-
The text was updated successfully, but these errors were encountered: