Salesforce Customization Guide
This guide provides instruction on creating the custom fields that are required in order to enable the customer profile and sales order sync use cases to function end-to-end.
Fields to Be Updated
The Order object needs to be updated for the following fields for the use case:
Field Name | Type | Updated Values |
---|---|---|
Type |
Picklist |
ADD_ON, CANCELLATION, INITIAL, JOURNAL, RENEWAL, RETURN, SUBSCRIPTION, UPGRADE |
Status |
Picklist |
CANCELLED, CREATED, CONFIRMED, DELIVERED, IN_CART, IN_TRANSIT, INVOICED, LOST, PARTIALLY_SHIPPED, PICKUP_AVAILABLE, PROCESSING, REJECTED, RETURNED |
Custom Objects
The following objects must be created
Salesforce Object Name | Singular Label | Plural Label |
---|---|---|
Managed_External_Id |
Managed External Identifier |
Managed External Identifiers |
Create Custom Objects Manually
-
In your Salesforce org, click Setup, and then select Setup to open Setup.
-
Click the Object Manager tab. If you don’t see it, enter Object Manager in the Quick Find box.
-
On the Object Manager page, click Create | Custom Object.
-
For Label, enter the value in
Singular Label
. -
For Plural Label, enter the value in
Plural Label
. -
Leave the rest of the values as default and click Save.
Create a Custom Object via Apex Script
An Apex class called CustomObjectUtility
and MetadataService
are used to create a custom object programmatically. The source can be found on Common Resources project and MetadataService respectively. Download the project and follow the steps below.
-
Click on the Salesforce Setup icon and select
Developer Console
to open a new console window. -
Go to
File > New > Apex class
and create a new class namedCustomObjectUtility
. -
Copy the code from
accel-common-resources/salesforce/CustomObjectUtility.apxc
to the script editor. -
Select the
Save
from the File menu option to compile and save the class. -
Go to
File > New > Apex class
and create a new class namedMetadataService
. -
Copy the code from
https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls
to the script editor. -
Select the
Save
from the File menu option to compile and save the class. -
Select
Debug > Open Execute Anonymous Window
. -
Copy and paste the contents of
/src/test/resources/scripts/CreateCustomObjects.txt
into the window. -
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 all fields have been created successfully.
Custom Fields
The following fields must be created in the corresponding objects.
Salesforce Object | Field Label | Field Name | Data Type | Length | Unique | ExternalId |
---|---|---|---|---|---|---|
Account |
Global Billing Address ID |
Global_BillingAddress_Id |
Text |
36 |
Y |
Y |
Account |
Global Customer ID |
Global_Customer_Id |
Text |
36 |
Y |
Y |
Account |
Global Email Address ID |
Global_EmailAddress_Id |
Text |
36 |
Y |
Y |
Account |
Global Fax Number ID |
Global_FaxNumber_Id |
Text |
36 |
Y |
Y |
Account |
Global Mailing Address ID |
Global_MailingAddress_Id |
Text |
36 |
Y |
Y |
Account |
Global Mobile Number ID |
Global_MobileNumber_Id |
Text |
36 |
Y |
Y |
Account |
Global Party ID |
Global_Party_Id |
Text |
36 |
Y |
Y |
Account |
Global Phone Number ID |
Global_PhoneNumber_Id |
Text |
36 |
Y |
Y |
Account |
Global Shipping Address ID |
Global_ShippingAddress_Id |
Text |
36 |
Y |
Y |
Account |
Customer Status |
Customer_Status |
Picklist |
- |
N |
N |
Managed_External_Id__c |
External Id |
External_Id |
Text |
80 |
N |
N |
Managed_External_Id__c |
External Id Type |
External_Id_Type |
Picklist |
- |
N |
N |
Managed_External_Id__c |
Object Id |
Object_Id |
Text |
80 |
N |
N |
Managed_External_Id__c |
Object Type |
Object_Type |
Picklist |
- |
N |
N |
Managed_External_Id__c |
Status |
Status |
Picklist |
- |
N |
N |
Managed_External_Id__c |
Status Last Changed |
Status_Last_Changed |
Date/Time |
- |
N |
N |
Contact |
Global_Individual_Id |
Global_Individual_Id |
Text |
36 |
Y |
Y |
Order |
Global_SalesOrder_Id |
Global_SalesOrder_Id |
Text |
36 |
Y |
Y |
Product2 |
Global_Product_Id |
Global_Product_Id |
Text |
36 |
Y |
Y |
Unique fields should be case-sensitive. |
Create via Apex Script
An Apex class called CustomFieldUtility
can be used to create custom fields programmatically. The source for this class can be found in the Accelerator Common Resources project. Download this project and follow the steps below.
-
Click on the Salesforce Setup icon and select
Developer Console
to open a new console window. -
Go to
File > New > Apex class
and create a new class namedCustomFieldUtility
. -
Copy the code from
accel-common-resources/salesforce/CustomFieldUtility.apxc
to the script editor. -
Select the
File > Save
menu option to compile and save the class. -
Select
Debug > Open Execute Anonymous Window
. -
Copy and paste the contents of
accel-common-resources/salesforce/CreateCustomFields.txt
into the window. -
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 Manually via Salesforce
To create each of these custom fields and enable visibility for them on page layouts:
-
Click on the Salesforce Setup icon.
-
Select the
Object Manager
tab from the Setup home page. -
Find and select the target Salesforce object.
-
Select the
Fields & Relationships
page. -
Click the New button and create the field as specified above.
-
Once the field has been created, click the
Set Field-Level Security
button (or do these steps later - see below). -
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 list.
Instead of adjusting permissions for each field as you go, 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.
|
Additional Notes
-
The Customer Status picklist values are Prospect, Onboarding, Active, Inactive, Closed, Deceased, Delinquent, and Dormant.
-
The External Id Type picklist values are SALESFORCE_B2C, SALESFORCE_CORE, PIM, OFBIZ, SAP_4HANA, MDM, SAP_ECC, SALESFORCE_MARKETING, and ORACLE_EBS.
-
The Object Type picklist values are BillingAddress, Customer, Email, Fax, Household, Individual, MailingAddress, MobilePhone, Organization, Phone, Product, SalesOrder, and ShippingAddress.
-
The Status picklist values are VALID, INVALID.
-
All
Global_*_Id__c
fields should be visible in layouts (as described above) but made read-only to avoid issues with data synchronization.
Configure Connected App for Authentication
Follow the below steps to generate the Consumer Key
and Consumer Secret
values required for Salesforce authentication.
-
Click on the Salesforce Setup icon .
-
Navigate to
Apps > App Manager
. -
Select
New Connected App
. -
Enter Connected App Name:
MuleSoft Accelerator
, API Name:MuleSoft_Accelerator
and set your email address. -
In the
API (Enable OAuth Settings)
section, check the boxEnable OAuth Settings
. -
Set the callback URL
http://localhost
. -
From the
Selected OAuth Scopes
list, selectFull access (full)
. -
Click Save and then Continue.
-
Click the Manage button to view details for the new connected app.
-
Click the Edit Policies button.
-
In the
OAuth Policies
section, forPermitted Users
selectAll users may self-authorize
. -
For
IP Relaxation
, select theRelax IP restrictions
option. -
Click Save.
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.fsc.client-id
and sfdc.fsc.client-secret
properties found in the Clouhub-RCG-DEV
profile in your Maven settings.xml
file.
-
On the Setup Home page, navigate to
Apps -> App Manager
. -
Locate your new connected app and choose View from the actions dropdown for that item.
-
In the API (Enable OAuth Settings) section, click the Manage Consumer Details button.
-
Verify your identity by entering the verification code that was emailed to you.
-
Copy the key and secret values and update your
settings.xml
file as described previously.
Download the Accelerator Common Resources project 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 FSC instance.
-
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).
-
Click the Username icon and select Settings from the menu.
-
Select
My Personal Information > Reset My Security Token
. If you cannot find this, see the note at the end of these steps. -
Click Reset Security Token.
-
Check the email inbox for an email from Salesforce with the new security token.
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. |
Contact Point Mappings
The following table lists the conditions used to assign ContactPoints in Salesforce:
CIM PartyRoleType - PartyType | Salesforce Object - Record Type | Condition | Action in Salesforce | Comments |
---|---|---|---|---|
Customer - Individual |
Account - PersonAccounts |
ContactPointAddress with |
Assign Address as |
If multiple addresses match this condition, the one with primaryFlag set to true is used; if none of them match this condition, then the first one is used |
Customer - Individual |
Account - PersonAccounts |
ContactPointAddress with |
Assign Address as |
|
Customer - Individual |
Account - PersonAccounts |
ContactPointAddress with |
Assign Address as |
|
Customer - Individual |
Account - PersonAccounts |
ContactPointPhone with |
Assign Phone Number as |
If multiple phones match this condition, the one with primaryFlag set to true is used; if none of them match this condition, then the first one is used |
Customer - Individual |
Account - PersonAccounts |
ContactPointPhone with |
Assign Phone Number as |
|
Customer - Organization |
Account - Account |
ContactPointAddress with |
Assign Address as |
If multiple addresses match this condition, the one with primaryFlag set to true is used; if none of them match this condition, then the first one is used |
Customer - Organization |
Account - Account |
ContactPointAddress with |
Assign Address as |
If multiple addresses match this condition, the one with primaryFlag set to true is used; if none of them match this condition, then the first one is used |
Customer - Organization |
Account - Account |
ContactPointAddress with |
Assign Address as |
|
Customer - Organization |
Account - Account |
ContactPointPhone with |
Assign Phone Number as |
If multiple phones match this condition, the one with primaryFlag set to true is used; if none of them match this condition, then the first one is used |
Customer - Organization |
Account - Account |
ContactPointPhone with |
Assign Phone Number as |
*The default value for all flags is false
.
Household Record Type
The following record type must be enabled if CIM PartyRole Customer
with Party as Household
needs to be supported, otherwise this step can be ignored.
Salesforce Object | Record Type |
---|---|
Account |
Household |
To enable the Household
record type in the Account
object, follow these steps:
-
Click on the Salesforce Setup icon.
-
Navigate to
Users → Profiles
. -
Select the target profile for the service account user.
-
Navigate to
Object Settings -> Accounts
and click the Edit button. -
Under
Record Types and Page Layout Assignments
check theHousehold
record type. -
Click the Save button.
Create Platform Events and Apex Triggers
The following Platform Event Objects 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 Objects are located in the Accelerator Common Resources project.
Salesforce Object | Salesforce Platform Event Object | Salesforce Platform Event API Name | Apex Trigger Name |
---|---|---|---|
Account |
Account |
Account__e |
AccountEventsPub |
Create Platform Event Object
This implementation requires Platform Events
to be created in Salesforce. Follow these steps to create a Platform Event
object:
-
Log in to Salesforce.
-
Click Setup and search for "Platform Events" in the Quick Find box. The Platform Events page shows with a list of available Platform Events.
-
Click the New Platform Event button to create an Object. Complete the Platform Information Details fields, including Label, Plural Label, Object with Object Name, and Event API Names as indicated in the previous table.
-
Click Save.
Repeat these steps to create additional Salesforce Platform Event objects as indicated in the previous table.
. To add Custom Fields & RelationShips to Platform Event Definitions, run the utility scripts (CreatePlatformEventsCustomFields.txt
) available in the Accelerator Common Resources in the /salesforce
folder.
Create Apex Triggers
Follow these steps to create the Apex Triggers:
-
Log in to Salesforce.
-
Click Setup to search for Object Manager in Quick Find Box.
-
Search for the Salesforce object. This opens a page that shows the details of the object.
-
Click Triggers in the Details section to view a list of available triggers for the object.
-
Click New.
-
Search for the Apex Trigger name, which is indicated in the previous table. Copy the Trigger Script code in
CreateApexTriggers.txt
from the Accelerator Common Resources page and paste it into the script editor. TheCreateApexTriggers.txt
file is located in the/salesforce
folder. -
Obtain the
LastModifiedById
andRecordTypeId
(if it exists) by running the queries mentioned in the trigger from the Developer Console. -
Replace the values in the script and save the trigger.
-
Click Save and ensure the isActive checkbox is checked.
-
Repeat these steps for each Salesforce object in the previous table.
Additional Notes
-
Each of the Apex Triggers that are created from the table filter records based on
LastModifiedBy <> {Service account ID}
. This is done to avoid cyclical updates performed by the Salesforce Customers API and Salesforce Financial System API. This can be obtained by running the querySELECT Id FROM User WHERE Username='<service-account-username>'
in the Developer Console. -
The Apex Trigger
AccountEventsPub
also filters records based on record type ID. The record type ID can be obtained by running the querySELECT Id,Name FROM RecordType where Name='Household' and 'sObjectType='Account'
in the Developer Console.