Upload a File to Salesforce and March Fields
Upload File And Link File To Salesforce Tape
- March ten, 2022
- ii:54 pm
- No Comments
Author: Harshitha Bhat
Utilize case
Once after receiving a file from source, the file should be uploaded to a respective Salesforce object.
This article volition show you how to upload a file and link that file to the respective salesforce object using its record Id.
Overall, the post-obit steps volition be performed:
- Upsert the file to Content Version object in Salesforce
- Retrieve ContentDocumentId from Content Version object
- Upsert the ContentDocumentId with respective tape Id/object Id to Content Document Link object
Build Menstruation in Anypoint Studio
- Open Studio and create a new project.
- In this case, project name is upload-file-to-salesforce
- In your projection, drag and drop the HTTP listener.
- In this project, file content is sent as multipart/form-data through postman, which tin exist seen in the following article.
- Configure the HTTP listener configuration.
- Click on the plus button, as shown in the below screenshot.
- Add the respective values to run your project on the local system as shown below in the screenshot and test connection, and click OK.
- Protocol: select HTTP
- Host: select All Interfaces [0.0.0.0] (default)
- Port: 8081
- Specify the path every bit an /upload for the HTTP listener.
- Extracting the file content from payload (of type multipart/form-data received from postman) and storing it under variable initialPayload.
- Add Transform Message and rename it as Transform payload to Content Version object type
- Create a variable called payloadForContentVersion
- Add the below dataweave script to this payloadForContentVersion variable.
- Add together variable chosen object_id into transform bulletin, which contains the tape Id of the salesforce object.
- Configure Salesforce Upsert – ContentVersion
- The next step is to perform the Salesforce Upsert operation. This volition take the file and upsert the data into the ContentVersion object.
- Drag and drib Upsert component to the menses
- The next step is to perform the Salesforce Upsert operation. This volition take the file and upsert the data into the ContentVersion object.
- Click on the plus sign next to the Connector configuration dropdown field in the Bones Settings section.
- Fill in the following fields under the General tab for a Basic Authentication connexion:
- Username
- Countersign
- Security Token
- Click on OK
- In the Mule Properties window, prepare the fields to the following values.
- Object Blazon: ContentVersion
- External id field name: Id
- Records: vars.payloadForContentVersion (which contains the payload prepared for contentVersion object)
- Storing the payload returned past upserting payload to contentVersion nether variable called contentVersion
- Add together Salesforce Query component and rename it as Retrieve Content Document Id
- After the file has been uploaded to the ContentVersion object, we need to get the Content Document Id that gets generated by Salesforce.
- To retrieve that Content Certificate Id, query ContentDocumentId object.
- The Connector configuration field will populate with the configuration that we gear up in the previous step.
- Under salesforce query tab, paste the following SOQL script:
- SELECT ContentDocumentId FROM ContentVersion WHERE Id = ':Id'
- Under the Parameters tab, click on the plus sign and add the following.
- Name – "Id"
- Value – vars.contentVersion.items[0].id
- Store the payload returned from Remember Content Document Id (salesforce query component) to variable chosen contentDocument
- Add 'Transform Message' and rename it to Transform payload to Content Certificate Link object type.
- Information technology takes the ContentDocumentId from the query and a record Id (from the object_id variable) of the object and maps that to a ContentDocumentLink object that will be upserted into Salesforce.
- Add Salesforce Upsert and rename information technology to Create Content Document Link
- Drag and drib Upsert component to the flow
- The Connector configuration field volition populate with the configuration that we set up in the previous footstep.
- In the Mule Backdrop window, fix the fields to the post-obit values.
- Object Type: Content Document Link (ContentDocumentLink)
- External id field proper name: Id
- Records: vars.payloadForContentDocumentLink (which contains the payload prepared for contentDocumentLink object)
- Storing the payload returned by upserting payload to contentDocumentLink under variable called contentDocumentLink
- The payload returned by this upsert performance is as follows.
- Add Set Payload and rename it to Set response payload (Optional)
- To correspond the payload with necessary fields, response payload is mapped with created, success and id fields.
Deploy and run
- Right-click on the canvas and select Run project <projection name>
- In one case the projection is deployed, switch to your postman
- Select method as Postal service
- Set URL with http://localhost:8081/upload
- Click on torso and select form-information
- Specify file nether cardinal by selecting File under the dropdown list
- Click on Select Files and select the file from file explorer.
- Click on Send
- Next, switch to your Salesforce instance and login
- Navigate to the Files navigation item to see the uploaded file
Source: https://apisero.com/upload-file-and-link-file-to-salesforce-record/
0 Response to "Upload a File to Salesforce and March Fields"
Post a Comment