Uploading and Attaching Documents with Salesforce SOAP API
In this process flow, we are going to walk you through the steps of uploading salesforce documents via Salesforce SOAP API.
As an example, the process flow picks up a file from a source folder, encodes the file into Base64 binary, and finally uploads the file or attachment into a specific folder or record in Salesforce. The Process Flow uses the Salesforce SOAP API and executes the Create function on Document or Attachment object types.
SOAP API is a standard communication protocol that enables users create, retrieve, update or delete records, such as accounts, leads, and custom objects. It makes it easier for business users to upload attachment or document in Salesforce without difficulty.
The Document object is used to upload Salesforce API attachment to a folder. Attachment object attaches documents to a specific record. For better understanding, the entire flow of uploading and attaching documents with Salesforce SOAP API must be known.
The high-level steps to configure the solution are:
- Define the Web Service Consumer activity using the Salesforce SOAP Enterprise WSDL
- Generate the WSDL by logging into Salesforce > Setup > Develop > API
- Download the WSDL file and go to Adeptia > Develop > Services > Web Service > Consumer and create the SOAP activity
- Create a Login sub-process that would call the Salesforce Login function and receives the serverUrl and sessionID. These two parameters are going to be passed to the subsequent Create function call in the Parent flow.
- Create a Parent process flow that would call the Login sub-process and passes the returning session parameters to the Create function.
- Required values to be mapped in the Create operation with extension element Attachment are:
- Body (this is the base64 encoding of the document that will encode the file)
- Name (document name to appear for the attachment)
- ParentID (ID of the record)
- Refer to Attachment object documentation
- Required values to be mapped in the Create operation with extension element Document are:
- Folder ID of the Salesforce folder
- Body (this is the base64 encoding of the document)
- Name (document name such as BenefitSummary.pdf)
- Type (document file type such as pdf, csv, doc etc)
- Refer to Document object documentation
Here are the two process flows that are used in the setup of the File Upload to Salesforce SOAP API Integration solution.
In the above sub-process, we are calling the Salesforce Login and passing the username, password appended with a security token. The sub-process can be reused as a common template for additional Salesforce SOAP operations.
The response from the SOAP call contains serverUrl and sessionId that we are setting as set-parent-context via a custom plugin. This plugin sets the two variables and their values into the parent flow.
Here’s the parent flow that calls the Login sub-process and receives the sessionId and serverUrl, calls the Create function and passes the Create Document request (built via mapping) to the Salesforce web service call. As part of this process we are also setting the Header which needs to be passed to the SOAP service call.
One of the key steps in the process flow is the Create Document mapping activity. There are few important mapping rules that we need to note so that the document is uploaded correctly in a particular folder in Salesforce with SOAP APIs.
Here the function we are using is the Base64 Binary Encoder function available in the Adeptia data mapping tool. In this function, you can pass the file name along with the file path or pass a context variable that contains the file location or data that needs to be encoded dynamically.
Additional fields that are required are Folder ID and Name of the file. Apply filter-unmapped elements on the rest of the fields. To get the Folder ID, you can create another simple flow in Adeptia that pulls the list of all the folders in your Salesforce account. You can take the Folder Id and pass this value in the mapping.
Name of the file is required. This would be the document name that would be shown in the folder. Also, note that the folder in Salesforce must have read/write permissions.
Here’s a snapshot of the document uploaded to a folder in Salesforce through this Salesforce SOAP API Integration solution.
Here’s a snapshot of a document attached to a record through this solution.
We have attached the process flows that are needed to upload documents in Salesforce with SOAP APIs (4mb). Please use the migration utility to migrate the flows into your local Adeptia instance.