Custom Header in Salesforce Component in Mule 4

Salesforce Connector:

Salesforce connector is a component available in Mule for consuming the operations and functionalities from a Salesforce System. While creating an application we can use the functionality of Salesforce connector to do Salesforce events such as adding, changing, deleting etc.
Salesforce connector can enable the connectivity to the Salesforce APIs. Such as SOAP API, REST API, Bulk API and Streaming API.REST APIs most of the time use APEX classes.

Salesforce Connector in Anypoint Studio



Use Case:

Create a User Account with few fields and trigger a rule on creating User.

Steps:

  1. Create a flow and add Create Salesforce operation
  2. Specify the object as Account and pass the payload
  3. This operation will make a API call internally and for calling an API requires few things:
  1. Authentication
  2. Required Parameters
  3. Optional Parameters
  4. Header
  5. Body

Take a sample configuration for creating an Account in Salesforce is given below:



Once we complete the execution of the flow you will receive a success message, however it will not trigger the requested rule as the required headers are not passed.

Solution:

In Salesforce we have different types of Headers available and we can pass those values through the header part in Salesforce connector.

Salesforce Headers:
1.Assignment Rule Header

The Assignment Rule header is a request header applied when creating or updating Accounts, Cases, or Leads. If enabled, the active assignment rules are used. If disabled, the active assignment rules are not applied. If a valid AssignmentRule ID is provided, the AssignmentRule is applied. If the header is not provided with a request, REST API defaults to using the active assignment rules.

2.Call Options Header

Specifies client-specific options when accessing REST API resources. For example, you can write client code that ignores namespace prefixes by specifying the prefix in the call options header.

3.Limit Info Header

This response header is returned in each request to REST API. You can use the information to monitor API limits.

4.Package Version Header

Specifies the version of each package referenced by a client. A package version is a number that identifies the set of components and behavior contained in a package. This header can also be used to specify a package version when making calls to an Apex REST web service.

5.Query Options Header

Specifies options used in a query, such as the query results batch size. Use this request header with the Query resource.

How to pass headers in Salesforce connector:

  1. Go to Salesforce connector
  2. Advance tab -> Headers
  3. Enable Headers as Expression
  4. Pass the required header in a JSon Format
  5. Execute again

Use the below picture as a sample reference