101.13 Advanced Automation Guide / Flows: Define Targeting Sets for Media Buying and use them for automatic creation of Buying Item targeting.
1. Overview & Purpose
This guide provides a detailed walkthrough for creating a custom automation using Salesforce Flow. The focus is on a common Media Buying requirement: applying a standardized list of postal codes to a campaign item.
The goal is to build a "low-touch" workflow where a campaign planner can select a pre-defined geographical region (e.g., "Germany - Northern Postal Codes") as a Targeting Set. The system will then automatically merge this postal code list with the item's base targeting, creating a new, fully configured Buying Item ready for trafficking. This reduces manual data entry, ensures accuracy, and standardizes regional targeting across campaigns.
2. The Use Case Scenario
A campaign planner is setting up a Media Buying Campaign Item for a retail client. The base targeting is for Device Type: Smartphone. The client wants this campaign to run only in their "Northern Sales Region," which corresponds to a specific list of 50 postal codes.
Instead of manually entering these 50 postal codes, the operations team has already created a Targeting Set named "Germany - Northern Postal Codes" containing this list.
The planner simply sets the base targeting (Smartphones) on the Campaign Item and selects the "Germany - Northern Postal Codes" Targeting Set.
Our Flow will then automatically:
Detect that the Campaign Item is ready for processing.
Create a corresponding Buying Order.
Intelligently merge the base "Device Type: Smartphone" targeting with the list of 50 postal codes from the Targeting Set.
Create a final Buying Item with a single, unified targeting configuration that includes both the device and all 50 postal codes, ready for submission to a DSP.
3. Prerequisites & Foundation
Before building the Flow, ensure the following is configured in your ADvendio org:
Media Buying Products: Your offerings must be set up as Ad Specs with the 'Buying' record type. This is the foundation for all media buying processes in ADvendio.
Postal Code Targeting Set: You must have a Targeting Set that contains the specific list of postal codes for your region (e.g., "Germany - Northern Postal Codes"). This is your reusable targeting template.
[Screenshot Placeholder: Detail page of a Targeting Set record named "Germany - Northern Postal Codes", showing a list of postal codes in its configuration.]
Page Layouts & Permissions: Users must have the necessary permissions and page layouts to assign Targeting Sets to Campaign Items.
4. Core Concept: The Merge Targeting Flow Action
The engine of our automation is the Merge Targeting Apex Action. It programmatically combines two targeting JSON strings into one.
For this specific use case, it's critical to note how it handles postal codes:
Inputs:
jsonString1(Required): The base targeting JSON (e.g., from the Campaign Item).jsonString2(Required): The targeting JSON from your Postal Code Targeting Set.targetingType(Optional): For merging postal codes, this must be set topostalcodes. This is required to correctly merge lists from theAdPostalCodesfield.
Outputs:
result: The final, unified targeting JSON string.status: The outcome, either "SUCCESS" or "ERROR".message: Provides details on the outcome, crucial for error handling.
Functionality: The action validates that both targeting sets belong to the same ADvendio Connection, preventing invalid combinations.
5. Step-by-Step Flow Build
This example outlines a Record-Triggered Flow that runs when a Campaign Item is ready for processing.
[Screenshot Placeholder: A high-level overview of the complete Salesforce Flow canvas, showing the main elements from Trigger to the final Create Records step.]
Flow Trigger:
Object: Campaign Item (
ADvendio__Campaign_Item__c)Trigger: A record is created or updated.
Entry Conditions:
Status = 'Ready for Automation'ANDNumber_of_Targeting_Sets__c > 0.[Screenshot Placeholder: The configuration window for the Flow's Start element, showing the Object and entry conditions being set.]
Step 1: Get Selected Targeting Sets
Add a Get Records element.
Object: The junction object that links Targeting Sets to your Campaign Items (e.g.,
TargetingSetAdSpecAssignment__c).Condition:
Campaign_Item__c = {!$Record.Id}.How Many Records: "All records".
[Screenshot Placeholder: The configuration window for the "Get Records" element, showing how to fetch the related Targeting Set assignments.]
Step 2: Loop Through Targeting Sets
Add a Loop element to iterate through the collection of assigned Targeting Sets found in Step 1.
[Screenshot Placeholder: The configuration window for the "Loop" element, showing the selection of the record collection variable to iterate over.]
Step 3: The Merge Action (Inside the Loop)
Inside the loop, add an Action element and select Merge Targeting.
Configure Inputs:
jsonString1: For this example, let's assume the base targeting is standard (e.g., Device), so you would provide the{!$Record.ADvendio__AdServerTargeting__c}.jsonString2: Provide the targeting string from the current Postal Code Targeting Set in the loop.targetingType: Enter the text valuepostalcodes. This is essential for this use case.
Store Outputs: Manually assign the
result,status, andmessageoutputs to new text variables for use later in the Flow.[Screenshot Placeholder: The configuration window for the "Merge Targeting" Apex Action, with the inputs for
jsonString1,jsonString2, andtargetingTypeclearly filled out according to the example.]
Step 4: Decision - Check for Merge Success
Add a Decision element to check the
statusoutput from the merge action.Outcome 1 (Success):
status = 'SUCCESS'.Outcome 2 (Default/Error): Handle the error, for example by logging the
messageoutput.
Step 5: Create Buying Order (After the Loop)
Once the loop is complete, add a Create Records element.
Object: Buying Order (
ADvendio__BuyingOrder__c).Map necessary fields from the source Campaign Item.
Step 6: Create Buying Item (Final Step)
Add a final Create Records element.
Object: Buying Item (
ADvendio__BuyingItem__c).Map Fields:
Link it to the Buying Order from Step 5.
Copy relevant details (Name, Dates, etc.) from the source Campaign Item.
Set the postal code targeting field (e.g.,
AdPostalCodes__c) to theresultvariable from your successful merge action.Set the standard targeting field (
SelectedTargeting__c) to the base targeting from the Campaign Item ({!$Record.ADvendio__AdServerTargeting__c}).
[Screenshot Placeholder: The field mapping screen for the "Create Records" element for the Buying Item, highlighting the
AdPostalCodes__candSelectedTargeting__cfields being populated from Flow variables.]
6. Important Considerations & Best Practices
Error Handling: Always build a path in your Flow for when the merge
statusis "ERROR". Use themessageoutput to log details for troubleshooting.Separate Targeting Fields: Note that standard targeting (Device, Geo, etc.) is often stored in a different field (
AdServerTargeting__c) than postal code targeting (AdPostalCodes__c). The merge action prepares the JSON, but yourCreate Recordelement must place that JSON in the correct field on the Buying Item.Test Thoroughly: Test your Flow with various combinations to ensure the merge behaves as expected for your specific use cases. Verify that the final Buying Item contains both the base targeting and the postal codes from the Targeting Set.