Get file attachments from Salesforce to BLOB


Problem Statement:

· To get the data from Salesforce to Azure Blob Which Service will be suitable, Why?

· Logic Apps is Suitable.

· Why not ADF, because we need to write a lot of code and commands to complete the process and will get the data from custom objects.

· If user wants to get the same data in the form of attachments, it will not be possible by using ADF.

Solution:


· By using logic azure logic apps we can create the attachments in salesforce from Azure BLOB in file format.

· In a single execution we can get the multiple files from salesforce.

· We do not need to charge the flow for different types of files.

Process diagram:




Advantages:

· We can process it for huge files from BLOB to Salesforce.

· We can process N no.of number of files.

· Times saving as we need not write the huge code to get the data.

Disadvantage:


· There is no security or authentications are needed to create the attachments in salesforce.

Flow Process:

 First, we need to create one salesforce account and then we need to upload files in salesforce.



Step1:
HTTP Request:


· The request trigger creates a manually callable endpoint that can handle only inbound requests over HTTPS.



Step 2
Initialize Variable:


· It is used to store the reusable data in the type of string, array, object, Boolean, integer.

· Here we are storing initial value as 0. Because to send multiple files into sales force. I Need to compare how many files in blob for that I am taking initial value as 0.



Step3
Get Records:


· It is used to retrieve the records in objects from salesforce.

· Here I’m retrieving the attachment as a record in Content Versions Object from salesforce.

· To retrieve an Attachment data from the salesforce. I’m passing the query along with these parameters Id, Path on client, Version Data, Filetype and I’m passing filter query to get the particular file.



[

{

"@odata.etag": "",

"ItemInternalId": "9c85746f-e0fe-4e81-836f-331aca3b2989",

"FileType": "JSON",

"Id": "0685i000006U1SeAAK",

"PathOnClient": "sample4.json",

"VersionData": "/services/data/v41.0/sobjects/ContentVersion/0685i000006U1SeAAK/VersionData"

},

{

"@odata.etag": "",

"ItemInternalId": "3cbd88c8-d3f0-4416-8ec9-318755536cdb",

"FileType": "TEXT",

"Id": "0685i000006U1SuAAK",

"PathOnClient": "sample1.txt",

"VersionData": "/services/data/v41.0/sobjects/ContentVersion/0685i000006U1SuAAK/VersionData"

}

]

Step 4
Initialize Variable:


· It is used to store the reusable data in the type of string, array, object, Boolean, integer. I’m storing array size here I have written length is the function by using this function we get the count of an array.



· Here I am storing version data and Path on Client.

Step 5

PathOnClient: Filename +File Extension (Sample. json)

Step 6


Version Data: File Content in the form of Base64.


Step 7
HTTP:


· If we need to get files from sales force to blob, we need to give the Authentication type, so we need to generate access token in sales force.

· For creating access token, we need to client id, client secrete, user id, password, grant type. From these we can generate access token.



· So, in this http connector I have taken the salesforce url and method as post.

· In next step I am storing the access token here.



· In initialize variable I’m storing the data



Step 8
Until:


· In until I have taken initial value is equal to array size, so that until loop will be executed based on the array size.

Note: we cannot initialize new variables in until scope. We can utilize the already initialized variables in the top of flow by using set variable connector.



Step 9
Version Data:


· In Until loop I have used set variable to store version data dynamically.



Step 10
Path On Client:


· In another variable I have used path on client to store path on client dynamically.



Step 11
HTTP-2:

Method: Get

URI: Salesforce Domain +Version Data

Authentication Type: Raw -Authorization: Bearer + access token




Step 12
Condition
: I am differentiating the files based on file types by using condition connector. If the file data is ends with .pdf or .xlsx files, the true condition will get satisfied. In true condition we are storing the file data which is getting from http as $content.



Create blob: It is used to store a file in specific folder in blob.




False condition: If the file path is ends with .csv, .json, .txt, files, the false condition will get satisfied. In false condition we are storing the file data which is getting from decode base64 http as $content.

Create blob: It is used to store a files in specific folder in blob.



Step 12
Increment variable
: Here we are incrementing the initial value by 1.



By using the above flow, we are able to get the attachments from Salesforce to BLOB.


finally, we get the output of multiple files from salesforce to the azure blob storage.


Comments