---
schema_version: "1"
id: 5aac8b77afa1998ddffef45cca8ea32a34928081cdb0558dde38bcb1baa80b43
title: Salesforce Customization Guide
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/retail/latest/rcg-sfdc-customization-guide.md
canonical_url: https://docs.mulesoft.com/retail/latest/rcg-sfdc-customization-guide
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e676b14ffdda70ff067dc48c32e61e493e2d673d18d45f8dc2c73c4011e6a85c
description: MuleSoft Documentation Site
release: "3.2"
latest: true
---
---
product: Retail
version: 3.2
is-latest-version: true
---

# Salesforce Customization Guide

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This guide provides the Salesforce customizations that must be created to enable the Customer 360,
Product, and Sales Order Sync use cases to function end-to-end.

## Create Custom Objects

The following objects must be created manually or via Apex script:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Salesforce Object Name</th><th>Singular Label</th><th>Plural Label</th></tr></thead><tbody><tr><td><p>Managed_External_Id</p></td><td><p>Managed External Identifier</p></td><td><p>Managed External Identifiers</p></td></tr></tbody></table>

### Create Custom Object Manually

1.  From Setup In your Salesforce org, click the Object Manager tab. If you don’t see it, enter
    "Object Manager" in the Quick Find box.

2.  On the Object Manager page, click Create | Custom Object.

3.  For Label, enter the value in `Singular Label`.

4.  For Plural Label, enter the value in `Plural Label`.

5.  For Object Name, enter the value in `Salesforce Object Name`.

6.  Leave the rest of the values as default and click Save.

### Create Custom Object via Apex Script

Use the\`CustomObjectUtility\` and `MetadataService` Apex classes to create a custom object
programmatically. The source is on the
[RCG Common Resources](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src/)
project and
[MetadataService](https://github.com/certinia/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls)
respectively. Download the project and follow these steps:

1.  Click on the Salesforce Setup icon and select `Developer Console` to open a new console window.

2.  Go to `File > New > Apex class` and create a new class named `CustomObjectUtility`.

3.  Copy the code from `rcg-common-resources/salesforce/CustomObjectUtility.apxc` to the script
    editor.

4.  Select the `Save` from the File menu option to compile and save the class.

5.  Go to `File > New > Apex class` and create a new class named `MetadataService`.

6.  Copy the code from
    `[https://github.com/certinia/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls](https://github.com/certinia/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls)`
    to the script editor.

7.  Select the `Save` from the File menu option to compile and save the class.

8.  Select `Debug > Open Execute Anonymous Window`.

9.  Copy and paste the contents of `rcg-common-resources/salesforce/CreateCustomObjects.txt` into
    the window.

10. Enable the `Open Log` option, and then click the **Execute** button.

Once the script completes, select the `Debug Only` filter option to show only the results of each
create request. Verify that custom object has been created successfully.

## Create Custom Fields

The following fields must be created in their corresponding objects manually or via Apex script:

<table><colgroup><col> <col> <col> <col> <col> <col> <col> <col></colgroup><thead><tr><th>Salesforce Object Label</th><th>Field Label</th><th>Field Name</th><th>Data Type</th><th>Length</th><th>Unique</th><th>ExternalId</th><th>Formula</th></tr></thead><tbody><tr><td><p>Account</p></td><td><p>Global Billing Address ID</p></td><td><p>Global_BillingAddress_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Customer ID</p></td><td><p>Global_Customer_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Email Address ID</p></td><td><p>Global_EmailAddress_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Fax Number ID</p></td><td><p>Global_FaxNumber_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Mailing Address ID</p></td><td><p>Global_MailingAddress_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Mobile Number ID</p></td><td><p>Global_MobileNumber_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Party ID</p></td><td><p>Global_Party_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Phone Number ID</p></td><td><p>Global_PhoneNumber_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Global Shipping Address ID</p></td><td><p>Global_ShippingAddress_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Account</p></td><td><p>Customer Status</p></td><td><p>Customer_Status</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>External Id</p></td><td><p>External_Id</p></td><td><p>Text</p></td><td><p>80</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>External Id Type</p></td><td><p>External_Id_Type</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Object Id</p></td><td><p>Object_Id</p></td><td><p>Text</p></td><td><p>80</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Object Type</p></td><td><p>Object_Type</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Status</p></td><td><p>Status</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Status Last Changed</p></td><td><p>Status_Last_Changed</p></td><td><p>Date/Time</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Order</p></td><td><p>Global_SalesOrder_Id</p></td><td><p>Global_SalesOrder_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Order</p></td><td><p>Total Tax</p></td><td><p>Total_Tax__c</p></td><td><p>Currency</p></td><td><p>-</p></td><td><p>-</p></td><td><p>-</p></td><td><p>-</p></td></tr><tr><td><p>Order</p></td><td><p>Shipping</p></td><td><p>Shipping__c</p></td><td><p>Currency</p></td><td><p>-</p></td><td><p>-</p></td><td><p>-</p></td><td><p>-</p></td></tr><tr><td><p>Order</p></td><td><p>Order Total Amount</p></td><td><p>OrderTotalAmount__c</p></td><td><p>Formula (Currency)</p></td><td><p>-</p></td><td><p>-</p></td><td><p>-</p></td><td><p>Shipping＿c + Total_Tax＿c + TotalAmount</p></td></tr><tr><td><p>Product</p></td><td><p>Global_Product_Id</p></td><td><p>Global_Product_Id</p></td><td><p>Text</p></td><td><p>36</p></td><td><p>Y</p></td><td><p>Y</p></td><td><p>-</p></td></tr><tr><td><p>Product</p></td><td><p>Product Group</p></td><td><p>Product_Catalog__c</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Product</p></td><td><p>Short Description</p></td><td><p>Short_Description__c</p></td><td><p>Text</p></td><td><p>255</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Product</p></td><td><p>Item Short Description</p></td><td><p>Item_Short_Description__c</p></td><td><p>Text</p></td><td><p>255</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Product</p></td><td><p>Item Long Description</p></td><td><p>Item_Long_Description__c</p></td><td><p>Text</p></td><td><p>255</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr><tr><td><p>Product</p></td><td><p>Status</p></td><td><p>Status__c</p></td><td><p>Picklist</p></td><td><p>-</p></td><td><p>N</p></td><td><p>N</p></td><td><p>-</p></td></tr></tbody></table>

> [!NOTE] Unique fields should be case-sensitive.

### Create Fields via Apex Script

Use the Apex class `CustomFieldUtility` to create custom fields programmatically. See the
[RCG Common Resources](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src/)
project to find the source for this class. Download the project and follow these steps:

1.  Click on the Salesforce Setup icon and select `Developer Console` to open a new console window.

2.  Go to `File > New > Apex class` and create a new class named `CustomFieldUtility`.

3.  Copy the code from `rcg-common-resources/salesforce/CustomFieldUtility.apxc` to the script
    editor.

4.  Select the `File > Save` menu option to compile and save the class.

5.  Select `Debug > Open Execute Anonymous Window`.

6.  Copy and paste the contents of `rcg-common-resources/salesforce/CreateCustomFields.txt` into the
    window.

7.  Enable the `Open Log` option and click the **Execute** button.

Once the script completes, select the `Debug Only` filter option to show just the results of each
create request. Verify that all fields have been successfully created.

### Create Fields Manually via Salesforce

To create each of these custom fields and enable visibility for them on page layouts:

1.  Click on the Salesforce Setup icon.

2.  Select the `Object Manager` tab from the Setup home page.

3.  Find and select the target Salesforce object.

4.  Select the `Fields & Relationships` page.

5.  Click the **New** button and create the field as specified above.

6.  Once the field has been created, click the `Set Field-Level Security` button (or do these steps
    later - see below).

7.  Enable for desired profile, or tick the checkbox next to `Visible` to enable visibility for the
    desired profile(s).

Repeat these steps for each custom field in the above table.

> [!NOTE]
>
> 1.  Instead of adjusting permissions for each field, if you are only making them available to one
>     or two profiles, then it may be more efficient to go to
>     `Users > Profiles > {profile} > Object Settings` for each object and adjust the permissions
>     for multiple fields at once.
>
> 2.  All `Global_*_Id__c` fields should be visible in layouts, as described previously, but made
>     **read-only** to avoid issues with data synchronization.

## Fields to Update

Follow these instructions to update the picklist fields that are listed in the table in the Custom
Fields section:

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Salesforce Object Label</th><th>Field Label</th><th>Field Name</th><th>Data Type</th><th>Values</th></tr></thead><tbody><tr><td><p>Order</p></td><td><p>Order Type</p></td><td><p>Type</p></td><td><p>Picklist</p></td><td><p>ADD_ON, CANCELLATION, INITIAL, JOURNAL, RENEWAL, RETURN, SUBSCRIPTION, UPGRADE</p></td></tr><tr><td><p>Order</p></td><td><p>Status</p></td><td><p>Status</p></td><td><p>Picklist</p></td><td><p>CANCELLED, CREATED, CONFIRMED, DELIVERED, IN_CART, IN_TRANSIT, INVOICED, LOST, PARTIALLY_SHIPPED, PICKUP_AVAILABLE, PROCESSING, REJECTED, RETURNED</p></td></tr></tbody></table>

To update the picklist values for a field in the specified object:

1.  Click **Setup**.

2.  Select the **Object Manager** tab.

3.  Search for and select the target Salesforce object.

4.  Select the **Fields & Relationships** page.

5.  Search for and select the target field with the field label.

6.  Select **New** in **Picklist Values**.

7.  Add the corresponding value from the **Values** column in the previous table, placing each
    picklist value on a separate line.

8.  Click **Save**.

Repeat these steps for each field in the table.

If you created the fields in the previous Custom Fields section manually, update the picklist values
for the fields in the table in the Fields to Update section.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Salesforce Object Label</th><th>Field Label</th><th>Field Name</th><th>Data Type</th><th>Values</th></tr></thead><tbody><tr><td><p>Account</p></td><td><p>Customer Status</p></td><td><p>Type</p></td><td><p>Picklist</p></td><td><p>Prospect, Onboarding, Active, Inactive, Closed, Deceased, Delinquent, Dormant</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>External Id Type</p></td><td><p>External_Id_Type__c</p></td><td><p>Picklist</p></td><td><p>SALESFORCE_B2C, SALESFORCE_CORE, PIM, OFBIZ, SAP_4HANA, MDM, SAP_ECC, SALESFORCE_MARKETING, POS, SALESFORCE_DC, SALESFORCE_LM, ORACLE_EBS</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Object Type</p></td><td><p>Object_Type__c</p></td><td><p>Picklist</p></td><td><p>BillingAddress, Customer, Email, Fax, Household, Individual, MailingAddress, MobilePhone, Organization, Phone, Product, SalesOrder, ShippingAddress</p></td></tr><tr><td><p>Managed External Identifier</p></td><td><p>Status</p></td><td><p>Status__c</p></td><td><p>Picklist</p></td><td><p>VALID, INVALID</p></td></tr><tr><td><p>Product</p></td><td><p>Product Group</p></td><td><p>Product_Catalog__c</p></td><td><p>Picklist</p></td><td><p>Basic, Premium</p></td></tr><tr><td><p>Product</p></td><td><p>Status</p></td><td><p>Status__c</p></td><td><p>Picklist</p></td><td><p>VALID, INVALID</p></td></tr></tbody></table>

## Configure Connected App for Authentication

Follow the below steps to generate the `Consumer Key` and `Consumer Secret` values required for
Salesforce authentication.

1.  Click on the Salesforce Setup icon .

2.  Navigate to `Apps > App Manager`.

3.  Select `New Connected App`.

4.  Enter Connected App Name: `MuleSoft Accelerator`, API Name: `MuleSoft_Accelerator` and set your
    email address.

5.  In the `API (Enable OAuth Settings)` section, check the box `Enable OAuth Settings`.

6.  Set the callback URL `http://localhost`.

7.  From the `Selected OAuth Scopes` list, select `Full access (full)`.

8.  Click **Save** and then **Continue**.

9.  Click the **Manage** button to view details for the new connected app.

10. Click the **Edit Policies** button.

11. In the `OAuth Policies` section, for `Permitted Users` select `All users may self-authorize`.

12. For `IP Relaxation`, select the `Relax IP restrictions` option.

13. Click **Save**.

14. Enable the OAuth 2.0 Username-Password Flow by following the steps documented in
    [Salesforce Help Docs](https://help.salesforce.com/s/articleView?id=release-notes.rn_security_username-password_flow_blocked_by_default.htm&release=244&type=5).

You now need to copy the `Consumer Key` and `Consumer Secret` values for use in configuring Mule
application deployments. More specifically, these must be supplied as the values for the
`sfdc.client-id` and `sfdc.client-secret` properties found in the `Clouhub-RCG-DEV` profile in your
Maven `settings.xml` file.

1.  On the Setup Home page, navigate to `Apps -> App Manager`.

2.  Locate your new connected app and choose **View** from the actions dropdown for that item.

3.  In the **API (Enable OAuth Settings)** section, click the **Manage Consumer Details** button.

4.  Verify your identity by entering the verification code that was emailed to you.

5.  Copy the key and secret values and update your `settings.xml` file as described previously.

Download the
[RCG Common Resources project](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src)
for a sample `settings.xml` file that can be used as a starting point.

## Generating a Security Token for the Service Account

A token needs to be generated for the service account used by the Mule applications in order to
connect to the Salesforce instance.

1.  Log in to Salesforce as the Service Account User, which is the account that will be used by the
    Mule applications to connect to Salesforce).

2.  Click the Username icon and select **Settings** from the menu.

3.  Select `My Personal Information > Reset My Security Token`. If you cannot find this, see the
    note at the end of these steps.

4.  Click **Reset Security Token**.

5.  Check the email inbox for an email from Salesforce with the new security token.

> [!NOTE] If the option to reset your security token is not available, it is likely that one or more
> Login IP Ranges are in effect. These can be temporarily removed from the settings page of the
> profile assigned to the service account user.

## Create Platform Events and Apex Triggers

The following Platform Event Object and Apex Triggers must be created in order to capture updates
from Salesforce. The scripts to create these Apex Triggers and add fields to Platform Event Object
are located in the
[RCG Common Resources](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src/)
project.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Salesforce Object</th><th>Salesforce Platform Event Object</th><th>Salesforce Platform Event API Name</th><th>Apex Trigger Name</th></tr></thead><tbody><tr><td><p>Account</p></td><td><p>Account</p></td><td><p>Account__e</p></td><td><p>AccountEventsPub</p></td></tr></tbody></table>

### Create Platform Event Object

This implementation requires `Platform Event` to be created in Salesforce. Follow these steps to
create a `Platform Event` object:

1.  Log in to Salesforce.

2.  Click **Setup** and search for "Platform Events" in the **Quick Find** box. The Platform Events
    page shows with a list of available Platform Events.

3.  Click the **New Platform Event** button to create an Object. Complete the **Platform Information
    Details** fields, including **Label**, **Plural Label**, **Object with Salesforce Object**, and
    **Salesforce Platform Event API Name** as indicated in the previous table.

4.  Click **Save**.

5.  To add Custom Fields & RelationShips to Platform Event Definitions, run the utility script
    `CreatePlatformEventsCustomFields.txt`, which is in the `rcg-common-resources/salesforce` folder
    of the
    [RCG Common Resources](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src/)
    project.

6.  Follow the steps to run the script provided in `Create via Apex Script` under `Custom Fields`.

### Create Apex Triggers

Follow these steps to create the Apex Triggers:

1.  Log in to Salesforce.

2.  Click Setup to search for Object Manager in Quick Find Box.

3.  Search for the Salesforce object. This opens a page that shows the details of the object.

4.  Click **Triggers** in the Details section to view a list of available triggers for the object.

5.  Click **New**.

6.  Search for the Apex Trigger name, which is indicated in the previous table. Copy the Trigger
    Script code `CreateApexTriggers.txt` from the `rcg-common-resources/salesforce` folder of the
    [RCG Common Resources](https://anypoint.mulesoft.com/exchange/org.mule.examples/rcg-common-resources-src/)
    project and paste it into the script editor.

7.  Obtain the `LastModifiedById` by running the query from the Additional Notes section.

8.  Replace the values in the script and save the trigger.

9.  Click **Save** and ensure the **isActive** checkbox is checked.

### Additional Notes

The Apex Trigger that is created filters records based on `LastModifiedBy <> {Service account ID}`
to avoid cyclical updates performed by the Salesforce Customers System API. Run the query
`SELECT Id FROM User WHERE Username='<service-account-username>'` in the Developer Console to obtain
Service account ID.

## See Also

- [Prerequisites](https://docs.mulesoft.com/retail/latest/prerequisites)

- [MuleSoft Accelerator for Retail](https://docs.mulesoft.com/retail/latest/)
