Updating Custom Metadata Type field in Salesforce with Mule 4

Edgar Moran
Another Integration Blog
4 min readNov 2, 2023

--

Photo by Kari Shea on Unsplash

Salesforce Custom Metadata Types (CMTs) are a powerful tool for customizing Salesforce to meet the specific needs of your business. CMTs allow you to define and store custom application metadata, such as picklist values, custom fields, and validation rules. This metadata can then be used to drive the behavior of your Salesforce org, such as by populating drop-down menus, validating data, and automating business processes.

Benefits of using Salesforce Custom Metadata Types

CMTs offer a number of benefits, including:

  • Flexibility: CMTs can be used to store a wide variety of data types, including text, numbers, dates, picklists, and relationships. This makes them highly flexible and adaptable to the needs of your business.
  • Reusability: CMTs can be reused across multiple objects and processes, making them a powerful tool for creating reusable code and functionality.
  • Maintainability: CMTs are stored in metadata, which makes them easy to maintain and upgrade. You can also use packages and the Metadata API to deploy and migrate CMTs between orgs.
  • Security: CMTs are protected by the same security permissions as other Salesforce objects. This means that you can control who has access to your custom metadata and how they can use it.

Use cases for Salesforce Custom Metadata Types

CMTs can be used for a variety of purposes, including:

  • Creating custom picklist values: CMTs can be used to create custom picklist values for standard and custom objects. This can be useful for things like creating custom product types, sales stages, or support priorities.
  • Defining custom fields: CMTs can be used to define custom fields for standard and custom objects. This can be useful for things like storing additional information about customers, products, or cases.
  • Creating validation rules: CMTs can be used to create validation rules for standard and custom objects. This can be useful for ensuring that data is entered correctly and consistently.
  • Automating business processes: CMTs can be used to automate business processes using Process Builder and Flow Builder. This can be useful for things like automatically creating tasks when a new case is opened or sending an email notification when a lead is converted into an opportunity.

How to create a Salesforce Custom Metadata Type

To create a Salesforce Custom Metadata Type, follow these steps:

  1. Go to Setup > Custom Metadata Types.
  2. Click New.
  3. Enter a name and description for your CMT.
  4. Select the field types that you want to use for your CMT.
  5. Click Save.

For this example I have created one that looks like this:

Please note that API Name and DeveloperName are couple important fields we will use later.

The Mule application

I have created a pretty simple application in Mule that only has one flow to demonstrate how we read the metadata and then we make the updates.

I created a Salesforce Developer Account and I’m using Basic Authentication (Username, Password, Token), consider for real life projects using JWT connection.

In the Read Metadata connector:

  1. Type : CustomMetadata (CustomMetadata) (CustomMetadata)
  2. FullNames: it should be [“Inventory__mdt.JAPAN”] or [YOUR_CMT_API_NAME.RECORD_NAME]

The result of this opertation will return the full CMT informtion from the Custom Metadata Type

For this example, I want to update the date field I created, for that we ned to define the DataWeave Transformation like this:

%dw 2.0
output application/java
---
[{
"fullName":"Inventory__mdt.JAPAN", //required
"label":"JAPAN", //required
"values": [{
"field":"Sync_Date__c",
"value": now()
}]
}]

Next we need to call the Update Metadata Connector, the connector configuration should be like this:

And the response should be a success unless errors happens

In Salesforce we can see our CMT record updated.

Important Considerations

In order to let Mulesoft update Metadata you need the next profile permissions:

  • API Enabled
  • Modify Metadata Through Metadata API Functions
  • Customize Application

--

--

Edgar Moran
Another Integration Blog

@Mulesoft Ambassador | Software Engineer @Cisco Meraki | Ex-Twitter | Sr. Force.com developer | innovating in technology, love coding, and photography !