Author: Vishal Kumar Singh & Vivek Singh
Salesforce Metadata
Metadata is information that describes other information. To understand how Salesforce defines metadata, let’s compare it with business data. Business data includes information directly related to a company’s operations, such as addresses, financials, or products. On the other hand, Salesforce metadata describes the architecture, processes, offerings, permissions, and general settings of your Salesforce organization.
Salesforce Metadata API
The Metadata API operates based on metadata types and objects. A metadata type defines the structure of application metadata, while metadata components serve as examples of metadata types. Both source and main metadata types fall under the umbrella of metadata. As an illustration, the CustomTab metadata type represents the Custom Tab used for displaying content.
The ‘hasSidebar’ field of the Custom Tab indicates whether the tab is present in the sidebar panel. This serves as an example where metadata influences the processing. Metadata types, such as Custom Tab, generate metadata that describes the style, appearance, or functionality of your organization. Utilize the Metadata API to build orchestrations and tools for managing the metadata structure itself, rather than the data it contains.
Custom Object Metadata
In Salesforce, custom object metadata refers to the objects, settings, and details of the structure or rules used to store and manage data specific to your organization. Product-specific metadata contains a set of elements that define the structure and behavior of the product.
Custom Field Metadata
Custom field metadata refers to the configuration and definition of objects or fields within standard objects. Custom fields are utilized to store and represent unique data. A custom metadata field contains a set of elements that describe its properties and behavior.
Salesforce Metadata Connectors
Create Metadata:
This connector can be used to create Salesforce Metadata like:
- Create Custom Object
- Create Custom Fields
- Create relationship
Note: You can find the key aspects for creating custom objects and fields in the official Salesforce documentation for the Metadata API here: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/customobject.htm
Prerequisites:
To create or update objects and fields in Salesforce from MuleSoft using the Salesforce Metadata API, the user must have a developer account. Additionally, the user making the API request needs to possess the necessary permissions in Salesforce. Here are the typically required permissions:
- Object Creation Permission
- Field Creation Permission
- CRUD Permissions
- API Access Permission
- Field-Level Security
The steps for creating objects and fields in Salesforce are as follows:
- To create an object or field, we will utilize the Salesforce ‘create Metadata’ connector.

- The connector should be configured with the following settings:
Name | Type | Description | Default Value | Required |
Configuration | String | The name of the configuration to use. | X | |
Type | String | The Metadata Type to be created | X | |
Metadata Object | Array Of Object | A List of Map<String, Object> representing the Metadata to be created. | #[payload] |
- When creating an object, the field ‘Type’ should have the value ‘CustomObject’. For field creation, the field ‘Type’ should have the value ‘CustomField’.

Now, we need to set the payload for object creation:
[
{
"fullName": "MyFirstTestObject__c",
"deploymentStatus": "Deployed",
"description": "Test object with one field for eclipse ide testing",
"fields": [
{
"fullName": "Comments__c",
"description": "add your comments about this object here",
"inlineHelpText": "This field contains comments made about this object",
"label": "Comments",
"length": "32000",
"type": "LongTextArea",
"visibleLines": "30"
}
],
"label": "MyFirstTestObject",
"nameField": {
"label": "MyFirstTestObject Name",
"type": "Text"
},
"pluralLabel": "MyFirstTestObjects",
"sharingModel": "ReadWrite"
}
]
The following properties are mandatory when creating a field: fullName, Label, pluralLabel, deploymentStatus, and sharingModel. Additionally, the field key should contain an array of Salesforce fields that need to be created. In the mentioned example, we are creating a field named ‘Comments__c’ within the custom object ‘MyFirstObject__c’.
- Once you run the integration, you will receive a response confirming the successful creation of both the object and the field.

Additionally, you can visit salesforce.com to verify the created object.

- To create a field, please refer to the snippet and payload provided below:

[
{
"fullName": "MyFirstTestObject__c.CustomField__c",
"label": "CustomField",
"type": "Text",
"length": 100,
"required": false
}
]
In the above snippet, ‘fullname’ indicates that ‘CustomField__c’ will be created in the object ‘MyFirstTestObject__c’.
Below is an example of a custom field added to a standard object:
Account.MyAcctCustomField__c
- After running the integration, a new field will be created in the previously created object.


Upsert Metadata connector
- We will use this connector to update the metadata if it is already present and create it if it is not.

- The connector needs to have the following configuration
Name | Type | Description | Default Value | Required |
Configuration | String | The name of the configuration to use. | X | |
Type | String | The Metadata Type to be created | X | |
Metadata Object | Array Of Object | A List of Map<String, Object> representing the Metadata to be upserted. | #[payload] |
- For upserting an object, the ‘Type’ field will have the value ‘CustomObject’. For field updation, the ‘Type’ field will have the value ‘CustomField’.

Now, we need to set the payload for object update:
[{
"fullName": "MyFirstObject__c",
"deploymentStatus": "Deployed",
"description": "This is a test object whose description has been updated",
"pluralLabel": "MyFirstObjects",
"sharingModel": "ReadWrite",
"label": "MyFirstObject",
"nameField": {
"label": "MyFirstObject Name",
"type": "Text"
},
}]
The following properties are mandatory: fullName, Label, pluralLabel, deploymentStatus, and sharingModel. Additionally, the field key should contain an array of Salesforce fields that need to be created. In the above example, we are updating the description of the object.
- After running the integration, a new field will be created in the previously existing object.


- Similarly, for an object, we will use the above payload used in field creation, and we will also change the type in the connector to ‘CustomField’. After a successful run of the integration, the fields will be updated. For example, we have updated the type of the field created in the field creation demo to ‘Number’.
[{
"fullName": "MyFirstObject__c.CustomField__c",
"label": "CustomField",
"type": "Number",
"precision": 10,
"scale": 5,
"required": false
}]

