Uploading and Attaching Documents with Salesforce SOAP API
In this process flow, we are going to walk you through the steps of uploading and attaching 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 object 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 object or document in Salesforce without difficulty. In addition, SOAP API helps users prevent unauthorized access to messages transmitted and received from SOAP APIs.
SOAP API is a standardized protocol for communication, ensuring compatibility and interoperability across different platforms and programming languages. It offers robust security features, including encryption and authentication, ensuring secure transmission of data over networks, making it suitable for sensitive and confidential information.
The Document object is used to upload Salesforce SOAP 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.
Salesforce SOAP API provides access to a wide range of Salesforce features, enabling developers to perform complex operations such as data manipulation, metadata access, and workflow automation. Also, SOAP API offers enterprise-level security and authentication mechanisms, ensuring the protection of sensitive customer data and providing a secure integration environment.
The high-level steps to configure the Salesforce SOAP API 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 process of setting up 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 API 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 Salesforce object document uploaded to a folder through this Salesforce web services 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 (4 MB). Please use the migration utility to migrate the flows into your local Adeptia instance.