Upload a File to Salesforce and March Fields

Upload File And Link File To Salesforce Tape

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:

  1. Upsert the file to Content Version object in Salesforce
  2. Retrieve ContentDocumentId from Content Version object
  3. Upsert the ContentDocumentId with respective tape Id/object Id to Content Document Link object
Build Menstruation in Anypoint Studio
  1. Open Studio and create a new project.
    • In this case, project name is upload-file-to-salesforce
  1. 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.
  1. Extracting the file content from payload (of type multipart/form-data received from postman) and storing it under variable initialPayload.
  1. 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.
  1. 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.
      1. Drag and drib Upsert component to the menses
  1. Click on the plus sign next to the Connector configuration dropdown field in the Bones Settings section.
  2. Fill in the following fields under the General tab for a Basic Authentication connexion:
    • Username
    • Countersign
    • Security Token
  3. Click on OK
  1. 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)
  1. Storing the payload returned past upserting payload to contentVersion nether variable called contentVersion
  1. 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.
    1. The Connector configuration field will populate with the configuration that we gear up in the previous step.
    2. Under salesforce query tab, paste the following SOQL script:
      • SELECT ContentDocumentId FROM ContentVersion WHERE Id = ':Id'
    3. 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
  1. 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.
  1. 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.
    1. Object Type: Content Document Link (ContentDocumentLink)
    2. External id field proper name: Id
    3. 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.
  1. 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
  1. Right-click on the canvas and select Run project <projection name>
  2. In one case the projection is deployed, switch to your postman
    1. Select method as Postal service
    2. Set URL with http://localhost:8081/upload
  1. Click on torso and select form-information
    1. Specify file nether cardinal by selecting File under the dropdown list
  1. Click on Select Files and select the file from file explorer.
  1. Click on Send
  1. Next, switch to your Salesforce instance and login
  2. Navigate to the Files navigation item to see the uploaded file

hearnbeembigh.blogspot.com

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel