Example Messaging Relationship Setup: Creating Parent and Child Records from a Flat Source
This section provides details of an example messaging scenario that creates parent and child records from data in a spreadsheet.
In this scenario, we want to build a messaging relationship to transfer details from imported data to create custom expense reports and expense lines for field agent expenses. To do this, we will use a custom staging object called Imported Expense to store imported data and use this as our source object in our messaging relationship. Our custom target objects are called Expense Report (Field Agent) and Expense Line and have a master-detail relationship.
We can also use messaging to chunk the imported data into batches to limit the number of expense lines on an expense report. If a parent expense report for an expense line does not exist in the org, it is created automatically. This option requires a master-detail relationship between the target objects.
You are a finance officer and want to import a spreadsheet containing expense details to PSA so that you do not have to manually enter the information. You want to perform this task every Monday for the expenses that were submitted during the previous week. The spreadsheet contains rows that detail individual expense submissions. The following table shows an example of the data in the spreadsheet.
Resource | Project | Assignment | Expense Date | Type | Amount |
Currency |
---|---|---|---|---|---|---|
David Stone | Acme | Product Manager | 08/23/2021 | Car Rental | 200 | USD |
David Stone | Acme | Product Manager | 08/23/2021 | Personal Meals | 15 | USD |
David Stone | Acme | Product Manager | 08/24/2021 | Personal Meals | 17 | USD |
David Stone | Acme | Product Manager | 08/26/2021 | Personal Meals | 15 | USD |
Michael Woodward | MerlinTech | Project Lead | 08/23/2021 | Personal Meals | 20 | USD |
Olivia Jackson | Acme | Product Manager | 08/23/2021 | Car Rental | 50 | USD |
Olivia Jackson | Acme | Product Manager | 08/24/2021 | Personal Meals | 18 | USD |
Jacob Hutchinson | Acme | Product Manager | 08/24/2021 | Car Rental | 50 | USD |
Jacob Hutchinson | Acme | Trainer | 08/26/2021 | Lodging (Room and Tax) | 150 | USD |
Michael Woodward | MerlinTech | Project Lead | 08/24/2021 | Lodging (Room and Tax) | 135 | USD |
Olivia Jackson | MerlinTech | Project Lead | 08/26/2021 | Personal Meals | 19.50 | USD |
Olivia Jackson | MerlinTech | Project Lead | 08/27/2021 | Lodging (Room and Tax) | 160 | USD |
In this example, we want no more than three expense lines on a single expense report. We use the messaging relationship to specify that whenever data that matches a parent is created, a new expense report is created when the number of expense lines reaches three. For the information submitted above, seven expense reports are created.
Expense Report |
Resource | Project | Assignment |
Expense Line |
Expense Date | Type | Amount |
Currency |
---|---|---|---|---|---|---|---|---|
1 | David Stone | Acme | Product Manager | 1 | 08/23/2021 | Car Rental | 200 | USD |
2 | 08/23/2021 | Personal Meals | 15 | USD | ||||
3 | 08/24/2021 | Personal Meals | 17 | USD | ||||
2 | David Stone | Acme | Product Manager | 1 | 08/26/2021 | Personal Meals | 15 | USD |
3 | Michael Woodward | MerlinTech | Project Lead | 1 | 08/23/2021 | Personal Meals | 20 | USD |
2 | 08/24/2021 | Lodging (Room and Tax) | 135 | USD | ||||
4 | Olivia Jackson | Acme | Product Manager | 1 | 08/23/2021 | Car Rental | 50 | USD |
2 | 08/24/2021 | Personal Meals | 18 | USD | ||||
5 | Olivia Jackson | MerlinTech | Project Lead | 1 | 08/27/2021 | Lodging (Room and Tax) | 160 | USD |
2 | 08/26/2021 | Personal Meals | 19.50 | USD | ||||
6 | Jacob Hutchinson | Acme | Product Manager | 1 | 08/24/2021 | Car Rental | 50 | USD |
7 | Jacob Hutchinson | Acme | Trainer | 1 | 08/26/2021 | Lodging (Room and Tax) | 150 | USD |
Build a Solution Using Messaging
You can use messaging to send data from one record to both a parent and child record in a master-detail relationship.
The configuration used in this example is set up to show a simple use case:
- The staging object consists of text and date fields
- Target lookups contain unique values so only field mappings are used
You can configure more complex mapping scenarios, for example, using the advanced lookup field type or data transformation tables, if required. For more information about more complex mapping configurations, see Adding Mappings to a Messaging Relationship.
Before you begin creating relationships and mappings, you must make sure that:
- You have set up an Imported Expense staging object to temporarily store the data you import
- You have added a roll-up summary field to the Expense Report (Field Agent) object to display the number of child records on each parent
- An administrator has granted you permission to manage messaging data
We recommend that you create a custom tab for the Imported Expense object. This enables you to view and manage the imported data.
For more information about permissions and creating custom objects, fields, and tabs, see the Salesforce Help.
In this example, the Foundations (ERP) registered product will be used to represent the publication side of the messaging relationship where we specify the data we want to send. The PSA (PSA) registered product will be used to represent the subscription side of the messaging relationship where we specify how to save sent data.
If your org is already set up for messaging, registered product records might already exist for ERP and PSA.
For more information about how registered products are created, see Registered Products.
- Create a new message type for this scenario. For more information, see Creating Custom Message Types.
- On the message type, click Manage Relationship.
- Create a new publication and specify the product you're publishing from.
- Specify Imported Expense as the source object and select a unique identifier.
- Create a new subscription and specify the product that receives the data. In this example, PSA.
- For the subscription type, select Multiple Identifier References on Target.
- Specify Expense Report (Field Agent) as the target object.
- Enter the maximum number of child records for each target. For this example, enter 3. Whenever data that matches a parent is added, a new expense report is created when the number of expense lines reaches three.
- Specify the field that stores the target object's child record count. This is the roll-up summary field we created in the Prepare Your Org section.
- Click Save.
Target parent records are identified by the mappings at the top level of the mapping hierarchy. In our example, we want to add expense lines to a single expense report when the following values match, up to the maximum number of lines specified:
- Resource
- Project
- Assignment
Create mappings for each of these fields from the source to the target. For more information about mapping options, see Adding Mappings to a Messaging Relationship.
A parent data mapping enables you to define a target child object to send data to. In this example, we want to send data from imported expenses to:
- Expense reports, and
- Related expense lines
To do this, we first need to create a parent data mapping:
- On the relationship, click Add Mapping.
- Do not enter a message key.
- For the source type, select "Parent Data".
- Leave the target type as "Child Relationship".
- For the target child relationship, select the name of the related object. For example, "pse__Expense_Lines__r".
- For this example, do not select a child filter field.
- Select the record creation method to determine whether records are kept in sync. For this example, we don't need to synchronize records after the targets are created, so select "Always Add".
- Click Save.
Now that you've created a child relationship, you can add mappings to it. Without specific mappings on the child relationship for any required fields, no target records can be created.
For more information about mapping options, see Adding Mappings to a Messaging Relationship.
In this example, we want to send the following details from imported expenses to create expense lines on the relevant expense reports.
You add a child mapping to a child relationship in a very similar way to a messaging relationship.
On the relationship, click in the Parent Data child relationship row and click Add Child Mapping.
Create field mappings for each field you want to populate on the child record. In this example, create mappings for the following fields:
- Expense Date
- Type
- Amount
- Currency
For more information about adding child mappings, see Adding Custom Mappings from the FDN Mappings Component.
When you have created mappings, enable the publication and subscription associated with the message type.
For more information, see Enabling and Disabling Publications and Subscriptions.
Foundations activation methods enable you to quickly and easily define how you want to send messages. You can select from default automated methods, Salesforce flows, or custom code.
For this example, we want to send a message every time an imported expense record is created and want to use Foundations default actions to achieve this.
To do this:
- On the relationship, click Manage Activation.
- Select the Default activation method.
- Select the Immediate delivery method.
- Click Save. Foundations creates the relevant triggers required to send messages.
For more information about the available activation methods, see Activating a Messaging Relationship.
In this example, we've set messaging up to send data as soon as a record is created. If your delivery method specifies that you want to send messages asynchronously, you can set up a scheduled job to define when messages are sent.
To configure the Message Delivery job to run at a specified time each Monday:
- Click the Foundations Setup tab.
- Click the Scheduled Jobs subtab.
- In the Message Delivery row, click .
- In the Time section, specify the time you want the job to run.
- In the Day/Date section, select Every Monday.
- In the Month section, select Every Month.
- In the Year section, select Every Year.
- Click Apply Changes.
- Select the Scheduled checkbox for the Message Delivery row.
For more information, see Scheduling Message Delivery.
Import Data and Manage Messages
You can use the Salesforce Data Loader or Data Import Wizard to import the data into the Imported Expense staging object. Due to the process builder configuration, expense reports and expense lines will be created synchronously.
You can specify the type of messages you want to retain from the Message Logs subtab of the Foundations Setup tab.
When you're setting up and testing messaging initially, we recommend that you set the logging level to All. When your org is fully configured, Errors is sufficient. For more information, see Configuring Message Retention.
You can also view details of the messages you've retained to help you get started. For more information, see Monitoring Message Delivery.
When you have verified that your expense reports and expense lines have been created, you can delete the imported expense records.