Purpose of the article: This blog explains how to get updated and modified files from Salesforce to Azure blob storage.
Intended Audience: This article will help our Organizational level kind of developers working on Salesforce to Azure Blob Storage by using Logic apps.
Tools and Technology: Salesforce to Azure Blob Storage
Keywords: Getting multiple, modified, and updated files to Salesforce to Azure Blob storage by using logic apps.
Getting Multiple or Updated Files from Salesforce to Azure Blob Storage
Description: By using this logic app flow, we can create or update multiple files in Azure blob storage from Salesforce. If any new file is added to the Salesforce within a specific time, the Logic app flow will directly connect to the Salesforce and flow will be triggered. Through logic presented in the flow, the Salesforce attachment will be directly created into the Azure BLOB storage.
Flow diagram:
Step-1: First, we need to create a Salesforce account and upload files into it.
Steps to implement in logic apps:
Step-2:
When a record is created: when an updated or modified record is created in Salesforce, the connector is triggered and the new file is added to the blob storage.
Here I’m creating the attachment as a record in Content Versions Object in Salesforce. Content Versions is a standard Object in Salesforce that is used to store files or attachments.
Note: The file data content will be in the form of Base64.
To create an Attachment in the Salesforce, I’m passing the parameters Title, Path on Client, and Version Data.
Title: Filename
PathOnClient: Filename +File Extension (Sample. Json)
Version Data: File Content in the form of Base64.
The attachment will be created in the Salesforce; if we want to check the created attachment, use the content document id from the response and pass the same content document id in the Salesforce URL.
Step 3:
Here I’m passing version data and path on client dynamically.
Step 4:
Retrieve the attachments from Salesforce to Azure blob storage
To retrieve the attachment from Salesforce to Azure blob, our Azure account needs to integrate with Salesforce as an authorized account. To make our account authorized, we need to pass the access token from the HTTP request.
Access Token Generation: The following step is to generate an access token.
We need to pass the username, password, client id, client secret, and grant type as query parameters to the Salesforce token generation link.
After requesting the token generation link, an acknowledgment will be received.
Step 5:
Method: We use the GET method to retrieve data from files in Salesforce, pass authentication parameters, and then receive the data in octet format after executing the flow.
URI: Salesforce Domain + Version Data
Headers: Content -Type: “application/json”
Authentication Type: Raw -Authorization: Bearer + access token
Step 6:
Step 7:
Condition: I am differentiating the files based on file types by using a condition connector. If the file path ends with .pdf,.xlsx, .ppt,.png, etc., files, the true condition will be satisfied. In the true condition, we are storing the file data, which is got from HTTP as $content.
If the condition is true, the file will update into the Azure blob storage.
False condition: If the file path ends with .CSV, JSON, .TXT, files, the false condition will get satisfied. In a false condition, we are storing the file data that is getting from decode base64 HTTP as $content.
After executing the flow, the output of updated files from Salesforce will be placed in Azure blob storage.
References:
- https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-overview
- https://learn.microsoft.com/en-us/connectors/salesforce/
- https://salesforcefaqs.com/get-security-token-salesforce/
- https://learn.microsoft.com/en-us/azure/?product=popular
- https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http?tabs=standard
Author Bio:
Tejasree RACHURI
Associate Software Engineer - Enterprise- Integration
This is Tejasree RACHURI working as a Technical Consultant at Mouri Tech for the past 2.5 years. I have good experience in Azure Data Factory, Logic Apps, API Management, and Azure SQL.