Customize Two-Way Sync Product Mapping Flows (Salesforce v4.x.x and above)

Christoffer Utterborn
Christoffer Utterborn
  • Updated

Introduced new flows

In Oneflow package versions 4.xx and later, we have made some changes to Oneflow Mapping: Products flow and introduced three new flows to support the two-way synchronization of product fields between Salesforce and Oneflow. The Oneflow Mapping: Products flow manages the transfer of Salesforce product information to Oneflow contracts. The other new flows handle the synchronization of product updates from Oneflow to Salesforce. By default, these flows handle product updates for the Opportunity line item object, so if you are only using the Opportunity line item as a product in Salesforce and don’t need to change the default mappings, no need to customize these flows. If you want these flows to work with a different Salesforce object you use as a product, or if you need to adjust the default mapping, you may need to customize them.

NOTE

Before customizing the Two-Way sync flows, ensure you make the necessary customizations to the Oneflow Mapping: Products flow. Refer to the Customizing Product Mapping for Contracts (Salesforce v4.x.x and above) article for more information.

1. Oneflow Products Update Flow

This flow is designed to handle product updates from Oneflow to Salesforce (To get Oneflow product updates to related Salesforce products). By default, this flow handles the Oneflow to Salesforce updates for opportunity line items. However, you can customize this flow for any other object as well. You can find this flow at Setup > Process Automation > Flows > Oneflow Products Update

Flow inputs

There are 4 flow input parameters in this flow.

  • OneflowProducts - Updated Oneflow products converted into OFapp__OneflowProduct object type
  • ProductIds - Updated Oneflow product IDs
  • ProductSobjectTypes - All the SObject type names of the mapped products (If you map another Salesforce object as a product it will also be included here)
  • ProductAttributesThatCanBeSynced - Oneflow to Salesforce Sync enabled product attributes.

When you fetch Oneflow updates to Salesforce, this flow updates Oneflow to Salesforce sync-enabled product fields in the related Salesforce opportunity line items. Oneflow provides product field configuration for the following product attributes in the default flow configuration.

  • Name
  • Price 1 Base Amount
  • Price 1 Discount
  • Quantity Type
  • Quantity

NOTE

To enable or disable product attributes sync behavior, go to Oneflow Configuration > Product Attributes.

  1. Salesforce >> Oneflow: Activating this will start syncing product updates from Salesforce to Oneflow contracts (You have to click the update button to push updates to Oneflow contract).
  2. Oneflow >> Salesforce: Activating this will sync product updates from Oneflow to Salesforce (If the contract state is draft you have to click Fetch Oneflow Updates button to fetch updates from Oneflow. Otherwise, the updates will be automatically synced to Salesforce).

You can add additional mapping for Price 2 Base Amount and Price 2 Discount or change the existing mapping.

  • To add additional mappings for Price 2 Base Amount or Discount - Add a new assignment in the relevant flow path (Discount 2, Price 2) and assign the Opportunity field that you want to map with the Oneflow attribute. For example, you can assign Opportunity line item List price as Oneflow product price 2.
  • To change the existing mapping - Change the assigned opportunity property to the property that you want to map as a Oneflow attribute. Please note that the Opportunity field you are going to map with the OFapp__OneflowProduct field should be of the same data type (e.g., Number, Text, etc.).

2. Oneflow Handle Deselected Products Flow

This flow is designed to delete the products in Salesforce whenever a user deselects a product or sets the product quantity to 0 in a Oneflow contract. By default, this flow is based on the opportunity line items, but you can configure it for other Salesforce objects as well.

You can find this flow at Setup > Process Automation > Flows > Oneflow Handle Deselected Products

Flow input variables

  • OneflowContractProducts - Oneflow Contract Products to be updated
  • ProductsIds - Product IDs to be deleted
  • ProductSObjectType - SObject types of the mapped products (In default configuration only the value is OpportunityLineItem).

First, this flow queries all the products related to the input product SObject type and product IDs. After that, the flow assigns all the opportunity line items (deselected or quantity 0 products in the Oneflow contract) information to a new instance of OFapp__Oneflow_Deselected_Product__c object. OFapp__Oneflow_Deselected_Product__c object fields represent the Oneflow deselected product fields and mapped Salesforce product fields information. Whenever the user re-selects the product or adds a quantity greater than 0, we can recreate the opportunity line item in Salesforce again using the saved data in OFapp__Oneflow_Deselected_Product__c records.

In the default flow configuration, the following product attributes are mapped:

  • Oneflow contract product Id
  • Opportunity line item sales price
  • Opportunity line item discount
  • Opportunity line item quantity
  • Opportunity line item name
  • Opportunity line item Description
  • Opportunity line item Id
  • Opportunity line item product Id
  • Opportunity Id
  • Product SObject Type
  • Opportunity line item Quantity Type

NOTE

If you have changed the default mapping in OneflowProductLineItem by adding additional fields in the Oneflow Mapping: Products flow, make sure to create new fields in the OFapp__Oneflow_Deselected_Product__c object to save the corresponding field values.

Make sure to select the correct field type when creating new fields. After that, map the required field to the Opportunity line item field by adding a new assignment in the Create new Oneflow Deselected Product step.

At the end of the flow, the assigned objects are saved in OneflowDeselectedProductsList and output as NewCreatedOneflowDeselectedProducts record collection variable.

3. Oneflow Add Reselected Products

This flow handles product re-selection in Oneflow contract products. When you re-select a product or set the quantity to greater than zero in the Oneflow contract product and fetch the updates to Salesforce, the flow will recreate the product in Salesforce. By default, this flow is based on opportunity line items, but you can configure it for other Salesforce objects as well.

You can find this flow at Setup > Process Automation > Flows > Oneflow Add Reselected Products

Flow Input Variables

  • DeselectedProductIds: IDs of Oneflow deselected products.
  • OneflowContractProductsWithDeselected: Deselected Oneflow contract products.

When this flow executes, it fetches all Oneflow Deselected Products (OFapp__Oneflow_Deselected_Product__c) using the provided IDs, iterates over them, and creates new Opportunity Products accordingly.

Next, there is a loop to iterate over all the queried products (Loop Deselected Products) and a decision variable to filter the products that are opportunity line items based on the Deselected product SObject type (Which type of SObject Decision variable).

In the following step (New Opportunity Product Assignment Variable), the flow assigns the field values of the Oneflow Deselected Products to the OpportunityProduct Record Variable (Since it handles the opportunity line items by default).

If you have mapped additional opportunity line item fields or changed the default field mappings in the flows described above, ensure to make the necessary changes here as well.

Afterwards, the flow adds those opportunity line item instances to the NewOpportunityProductsCollection collection variable and adds the deselected products to the DeselectedProductsToBeDeleted collection variable. Then, the flow creates new opportunity line items using the NewOpportunityProductsCollection. The flow then queries those newly created products again and updates the relevant fields according to the OneflowContractProductsWithDeselected flow input. 

In the following step, it assigns the new line item IDs to the mapped Oneflow contract products and changes the Deselected field to False. In the final step, it commits the Oneflow contract products update section as a batch using the OneflowContractProductsToUpdate updated product list and outputs the DeselectedProductsToBeDeleted list.

Trigger for Deselected Products

You need to implement the trigger to handle push updates for product deletions in the Oneflow contract for other objects mapped as products. You don’t need to implement this for Opportunity Line Items, as it is already included in the Oneflow package.

  1. Create a trigger on the object you mapped as a product.
  2. Paste the following code (replace Account_Product__c with your object API name in all three places: trigger definition, loop variable, and trigger context):
trigger AccountProductTrigger on Account_Product__c (before delete) {
    Set<Id> ids = new Set<Id>();
    for (Account_Product__c item : Trigger.old){
        ids.add(item.Id);
    }
    OFapp.OneflowContractProductService oneflowService = new OFapp.OneflowContractProductService();
    oneflowService.updateOneflowContractProductsToBeDeleted(ids);
}

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request