Blogs
Salesforce Composite Connector 2.9 – Mule 4
- February 13, 2023
- MuleSoft
Anypoint Connector for Salesforce Composite enables you to work with the Salesforce Batch and Sobject Tree APIs. The connector exposes convenient methods for preparing subordinate requests, executing them in one batch, and parsing the results. Salesforce Composite Connector also enables you to create Sobject trees by using the Create sobject tree operation, which is separate from the batch operations. This connector provides DataSense for execution and to:
- Prepare subordinate requests and then parse the responses
- Create Sobject trees
Using Anypoint Studio to Configure Salesforce Composite Connector 2.9 – Mule 4.
Create a Mule Project.
In Studio, create a new Mule project in which to add and configure the connector
- Select File > New > Mule Project.
- Enter a name for your Mule project and click Finish.
Add the Connector to Your Mule Project.
Add Salesforce Composite Connector to your Mule project to automatically populate the XML code with the connector’s namespace and schema location and add the required dependencies to the project’s pom.xml file:
- In the Mule Palette view, click (X) Search in Exchange.
- In Add Modules to Project, type salesforce composite in the search field.
- Click Salesforce Composite in Available modules.
- Click Add.
- Click Finish.
Add a Connector Operation to the Flow.
When you add a connector operation to your flow, you immediately define a specific operation for that connector to perform. To add an operation for Salesforce Composite Connector, follow these steps:8.In the Mule Palette view, select Salesforce Composite and then select the desired operation.
9. Drag the operation onto the Studio canvas to the right of the input source.
Configure a Global Element for the Connector
When you configure a connector, it’s best to configure a global element that all instances of that connector in the app can use. Configuring a global element requires you to provide the authentication credentials that the connector requires to access the target Salesforce Composite system. Salesforce Composite Connector supports OAuth v2.0, OAuth JWT, OAuth SAML, and OAuth Username and Password. To configure the global element for Salesforce Composite Connector, follow these steps:
10. Select the name of the connector in the Studio canvas.
11.In the configuration screen for the operation, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.
12. On the General tab, in Connection, select the authentication method to configure:
- OAuth v2.0
- OAuth JWT
- OAuth SAML
- OAuth Username and Password
13. On the Advanced tab, optionally specify reconnection information, including a reconnection strategy.
14. Click Test Connection to confirm that Mule can connect with the specified server.
15. Click OK.
16. On the Advanced tab, optionally specify reconnection information, including a reconnection strategy.
17. Click Test Connection to confirm that Mule can connect with the specified server.
18. Click OK.
OAuth Username and Password
Enter the following information on the General tab of the Global Element Properties screen to configure Basic authentication:
- Consumer Key The consumer key for the Salesforce connected app
- Consumer Secret The consumer secret for the connector to access Salesforce
- Username The Salesforce username
- Password The corresponding password
Security Token The corresponding security token.
Example
SalesForce Composite Connector -Execute Batch Request | MuleSoft | Mule 4.3.0 Executing batch requests. Batch Executes up to 25 subrequests in a single request. The response bodies and HTTP statuses of the subrequests in the batch are returned in a single response body. Each subrequest counts against rate limits. The requests in a batch are called subrequests. All subrequests are executed in the context of the same user. Subrequests are independent, and you can’t pass information between them. Subrequests execute serially in their order in the request body. When a subrequest executes successfully, it commits its data. Commits are reflected in the output of later subrequests. If a subrequest fails, commits made by previous subrequests are not rolled back. If a batch request doesn’t complete within 10 minutes, the batch times out and the remaining subrequests aren’t executed.
- With the help of anyoint studio, we are able to do this example.
- Create a small project in the Anypoint studio.
- Within the salesforce composite, we can look for the composite batch i.e. (Execute composite batch) connector, just drag and drop that connector in the flow, then configure the same salesofr_composite_config which I have already given above how to configure the salesforce composite connector.
Keep the Transform message before the Execute composite batch. we have to send the payload as shown in the below picture, also we can modify the transform message according to our requirements.
As we can see in the above picture the account name (Shivam Trips) which we are going to update. - Run the program and give a hit from postman.
- We will get the response as shown in the below picture.
If you get the same response after hitting, your code is running properly and see the change in the salesforce account.