Salesforce dbt Package (Docs)
-
Produces modeled tables that leverage Salesforce data from Fivetran's connector in the format described by this ERD.
-
This package also provides you with the option to leverage the history mode to gather historical records of your essential tables.
-
This package enables users to:
- Understand the performance of your opportunities
- Drill into how the members of your sales team are performing
- Have a daily summary of sales activities
- Leverage an enhanced contact list
- View more details about opportunity line items
- Gather daily historical records of your accounts, contacts and opportunities
This package also generates a comprehensive data dictionary of your source and modeled Salesforce data via the dbt docs site You can also refer to the table below for a detailed view of all tables materialized by default within this package.
| Table | Description | Available in Quickstart? |
|---|---|---|
| salesforce__manager_performance | This table provides performance metrics by manager, showing team level pipeline, bookings, losses, and win rates. Example Analytics Questions: • What is the correlation between a manager's team size and their total bookings performance this quarter? • Which managers are struggling with pipeline conversion and would benefit from additional coaching or resources? |
Yes |
| salesforce__owner_performance | This table provides an enhanced view of individual sales team members, including metrics around bookings, pipeline, losses, and win percentage. Example Analytics Questions: • How does quota attainment vary by sales rep experience level and territory? • Which reps have high activity levels but low conversion rates, indicating potential training opportunities? |
Yes |
| salesforce__sales_snapshot | This table provides a single-row snapshot of current and all-time sales funnel metrics. Example Analytics Questions: • Are we seeing seasonal patterns in our sales performance that should inform resource allocation? • How does our current pipeline coverage compare to historical benchmarks for achieving quarterly targets? |
Yes |
| salesforce__opportunity_enhanced | This table enriches opportunities with data about the associated account and opportunity owner. Example Analytics Questions: • Which industries or account types generate the highest-value opportunities and shortest sales cycles? • Which opportunities have been open the longest and what intervention strategies could help close them? |
Yes |
| salesforce__contact_enhanced | This table enriches contacts with information about the associated account and contact owner. Example Analytics Questions: • Do opportunities with multiple engaged contacts close faster or larger? • Where are data hygiene gaps, such as opportunities missing a primary contact role? |
Yes |
| salesforce__daily_activity | This table provides a daily summary of sales activities related to the creation and conversion of leads, tasks, and opportunities. Example Analytics Questions: • How does the mix of tasks versus events impact overall sales productivity and outcomes? • Which days of the week or times of year show the highest conversion rates from activities to opportunities? |
Yes |
| salesforce__opportunity_line_item_enhanced | This table showcases individual line items belonging to opportunities and adds associated product details. Example Analytics Questions: • What were the most popularly bundled products last quarter across different customer segments? • Which accounts show early warning signs of churn based on historical patterns? |
Yes |
| salesforce__account_daily_history | This table provides a daily record of each account, starting with its first active date and extending to its last active date, or the current date if the account is still active. Example Analytics Questions: • How do account engagement levels fluctuate around contract renewal periods? • Are there events or account updates that often precede churn? |
No |
| salesforce__contact_daily_history | This table provides a daily record of each contact, starting with its first active date and extending to its last active date, or the current date if the contact is still active. Example Analytics Questions: • How do contact engagement patterns change throughout the sales cycle? • How do contact role changes within accounts impact ongoing sales opportunities? |
No |
| salesforce__opportunity_daily_history | This table provides a daily record of each opportunity, starting with its first active date and extending to its last active date, or the current date if the opportunity is still active. Example Analytics Questions: • What are the typical progression patterns for opportunities that ultimately close-won versus close-lost? • Which stage transitions take the longest and represent the biggest bottlenecks in our sales process? |
No |
Note: For Quickstart Data Model users only, in addition to the above output models that are Quickstart compatible, you will also receive models in your transformation list which replicate all of your Salesforce objects with the inclusion of the relevant formula fields in the generated output models.
Each Quickstart transformation job run materializes 23 models if all components of this data model are enabled. This count includes all staging, intermediate, and final models materialized as view, table, or incremental.
To use this dbt package, you must have the following:
- At least one Fivetran Salesforce connection syncing data into your destination.
- A BigQuery, Snowflake, Redshift, PostgreSQL, or Databricks destination.
If you are using a Databricks destination with this package you will need to add the below (or a variation of the below) dispatch configuration within your dbt_project.yml. This is required in order for the package to accurately search for macros within the dbt-labs/spark_utils then the dbt-labs/dbt_utils packages respectively.
dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']The history end models in this package are materialized incrementally. We have chosen insert_overwrite as the default strategy for BigQuery and Databricks databases, as it is only available for these dbt adapters. For Snowflake, Redshift, and Postgres databases, we have chosen delete+insert as the default strategy.
insert_overwrite is our preferred incremental strategy because it will be able to properly handle updates to records that exist outside the immediate incremental window. That is, because it leverages partitions, insert_overwrite will appropriately update existing rows that have been changed upstream instead of inserting duplicates of them--all without requiring a full table scan.
delete+insert is our second-choice as it resembles insert_overwrite but lacks partitions. This strategy works most of the time and appropriately handles incremental loads that do not contain changes to past records. However, if a past record has been updated and is outside of the incremental window, delete+insert will insert a duplicate record.
Because of this, we highly recommend that Snowflake, Redshift, and Postgres users periodically run a
--full-refreshto ensure a high level of data quality and remove any possible duplicates.
Include the following salesforce package version in your packages.yml
Check dbt Hub for the latest installation instructions, or read the dbt docs for more information on installing packages.
packages:
- package: fivetran/salesforce
version: [">=2.0.0", "<2.1.0"] # we recommend using ranges to capture non-breaking changes automaticallyAll required sources and staging models are now bundled into this transformation package. Do not include
fivetran/salesforce_sourcein yourpackages.ymlsince this package has been deprecated.
By default, this package will run using your target database and the salesforce schema. If this is not where your Salesforce data is, add the following configuration to your root dbt_project.yml file:
vars:
salesforce_database: your_database_name
salesforce_schema: your_schema_nameYour Salesforce connection may not sync every table that this package expects. If your syncs exclude certain tables, it is because you either don't use that functionality in Salesforce or actively excluded some tables from your syncs.
To disable the corresponding functionality in this package, you must add the corresponding variable(s) to your dbt_project.yml, which are listed below. By default, that is if none of these variables are added, all variables are assumed to be true. Add variables only for the tables you would like to disable:
vars:
salesforce__user_role_enabled: false # Disable if you do not have the user_role table
salesforce__lead_enabled: false # Disable if you do not have the lead table
salesforce__event_enabled: false # Disable if you do not have the event table
salesforce__task_enabled: false # Disable if you do not have the task table
salesforce__opportunity_line_item_enabled: false # Disable if you do not have the opportunity_line_item table
salesforce__order_enabled: false # Disable if you do not have the order table
salesforce__product_2_enabled: false # Disable if you do not have the product_2 tableThe corresponding metrics from the disabled tables will not populate in the downstream models.
If you do not have the OPPORTUNITY table, there is no variable to turn off opportunity-related transformations, as this table is largely the backbone of the Salesforce package.
However, you may still find value in this package without opportunity data, specifically in the salesforce__contact_enhanced, salesforce__daily_activity, salesforce__account_daily_history and salesforce__contact_daily_history (if using History Mode) end models.
For this use case, to ensure the package runs successfully, we recommend leveraging this Fivetran Feature to create an empty opportunity table. To do so, follow these steps:
- Navigate to your Salesforce connection in the "Connectors" tab within the Fivetran UI.
- Click on the "Schema" tab.
- Scroll down to
Opportunityand click on its checkbox to add it into your schema. - Click "Save Changes" in the upper righthand corner of the screen.
- Either click "Resync" for the
Opportunitytable specifically or wait for your next connection-level sync.
Note that all other end models (
salesforce__opportunity_enhanced,salesforce__opportunity_line_item_enhanced,salesforce__manager_performance,salesforce__owner_performance,salesforce__sales_snapshot, andsalesforce__opportunity_daily_history) will still materialize after a blanketdbt runbut will be largely empty/null.
If you have Salesforce History Mode enabled for your connection, we now include support for the account, contact, and opportunity tables directly. These staging models flow into our daily history models. This will allow you access to your historical data for these tables while taking advantage of incremental loads to help with compute.
To ensure maximum value for these history mode models and avoid messy historical data that could come with picking and choosing which fields you bring in, all fields in your Salesforce history mode connection are being synced into your end staging models. That means all custom fields you picked to sync are being brought in to the final models. See our DECISIONLOG for more details on why we are bringing in all fields.
To update the history mode models, you must follow these steps:
- Go to your Fivetran Salesforce History Mode connection page.
- Update the fields that you are bringing into the model.
- Run a
dbt run --full-refreshon the specific staging models you've updated to bring in these fields and all the historical data available with these fields.
We are aware that bringing in additional fields will be very process-heavy, so we do emphasize caution in making changes to your history mode connection. It would be best to batch as many field changes as possible before executing a --full-refresh to save on processing.
Customers with a Salesforce connection generally fall into one of two categories when taking advantage of History mode. They either have one connection that is syncing non-historical records and a separate connection that syncs historical records, or they have one connection that is syncing historical records. We have designed this feature to support both scenarios.
If you are gathering data from both standard Salesforce as well as Salesforce History Mode, and your target database and schema differ as well, you will need to add an additional configuration for the history schema and database to your dbt_project.yml.
vars:
salesforce_database: your_database_name # salesforce by default
salesforce_schema: your_schema_name
salesforce_history_database: your_history_database_name # salesforce_history by default
salesforce_history_schema: your_history_schema_namePerhaps you may only want to use the Salesforce History Mode to bring in your data. Because the Salesforce schema is pointing to the default salesforce schema and database, you will want to add the following variable into your dbt_project.yml to point it to the salesforce_history equivalents.
vars:
salesforce_database: your_history_database_name # salesforce by default
salesforce_schema: your_history_schema_name
salesforce_history_database: your_history_database_name # salesforce_history by default
salesforce_history_schema: your_history_schema_nameIMPORTANT: If you utilize Option 2, you must sync the equivalent enabled tables and fields in your history mode connection that are being brought into your end reports. Examine your data lineage and the model fields within the salesforce folder to see which tables and fields you are using and need to bring in and sync in the history mode connection.
The History Mode models can get quite expansive since it will take in ALL historical records, so we've disabled them by default. You can enable the history models you'd like to utilize by adding the below variable configurations within your dbt_project.yml file for the equivalent models.
# dbt_project.yml
vars:
salesforce__account_history_enabled: true # False by default. Only use if you have history mode enabled and wish to view the full historical record of all your synced account fields, particularly in the daily account history model.
salesforce__contact_history_enabled: true # False by default. Only use if you have history mode enabled and wish to view the full historical record of all your synced contact fields, particularly in the daily contact history model.
salesforce__opportunity_history_enabled: true # False by default. Only use if you have history mode enabled and wish to view the full historical record of all your synced opportunity fields, particularly in the daily opportunity history model.By default, these models are set to bring in all your data from Salesforce History, but you may be interested in bringing in only a smaller sample of historical records, given the relative size of the Salesforce History source tables. By default, the package will use 2020-01-01 as the minimum date for the historical end models. This date was chosen to ensure there was a limit to the amount of historical data processed on first run. This default may be overwritten to your liking by leveraging the below variables.
We have set up where conditions in our staging models to allow you to bring in only the data you need to run in. You can set a global history filter that would apply to all of our staging history models in your dbt_project.yml:
vars:
global_history_start_date: 'YYYY-MM-DD' # The first `_fivetran_start` date you'd like to filter data on in all your history models.If you'd like to apply model-specific conditionals, configure the below variables in your dbt_project.yml:
vars:
account_history_start_date: 'YYYY-MM-DD' # The first date in account history you wish to pull records from, filtering on `_fivetran_start`.
contact_history_start_date: 'YYYY-MM-DD' # The first date in contact history you wish to pull records from, filtering on `_fivetran_start`.
opportunity_history_start_date: 'YYYY-MM-DD' # The first date in opportunity history you wish to pull records from, filtering on `_fivetran_start`.Source tables are referenced using default names. If an individual source table has a different name than expected, provide the name of the table as it appears in your warehouse to the respective variable:
IMPORTANT: See the package's source
dbt_project.ymlvariable declarations to see the expected names.
vars:
<package_name>_<default_source_table_name>_identifier: your_table_nameBy default, this package builds all of the Salesforce models within your target.schema in your target database. If this is not where you would like your Salesforce data to be written to, add the following configuration to your root dbt_project.yml file:
models:
salesforce: # If you want everything written to one schema, you can scope the +schema config to the package level
salesforce:
+schema: my_new_schema_name # Will write Salesforce end models to <target_schema> + _my_new_schema_name
staging:
+schema: my_new_schema_name # Will write Salesforce staging models to <target_schema> + _my_new_schema_name
salesforce_history:
+schema: my_new_schema_name # Will write Salesforce History models to <target_schema> + _my_new_schema_name
staging:
+schema: my_new_schema_name # Will write Salesforce History staging models to <target_schema> + _my_new_schema_nameThis package allows users to add additional columns to the salesforce__opportunity_enhanced, salesforce__opportunity_line_item_enhanced,salesforce__contact_enhanced, and any of the daily_history models if you have Salesforce history mode enabled. You can do this by using the below variables in your dbt_project.yml file. These variables allow these additional columns to be aliased (alias) and casted (transform_sql) if desired, but not required. Datatype casting is configured via a sql snippet within the transform_sql key. You may add the desired sql while omitting the as field_name at the end and your custom pass-though fields will be casted accordingly. Use the below format for declaring the respective pass-through variables.
For the salesforce__opportunity_enhanced model, it joins in the user model two times, since an opportunity has both an owner and manager. The first time the user model is joined is to add information about an opportunity owner. The second time is to add information about an opportunity manager. Therefore to avoid ambiguous columns from joining in the same model twice, custom fields passed through from the user table will be suffixed based on whether it belongs to a user who is an _owner or a _manager.
Additionally, you may add additional columns to the staging models. For example, for passing columns to stg_salesforce__product_2 you would need to configure salesforce__product_2_pass_through_columns.
# dbt_project.yml
vars:
salesforce__account_pass_through_columns:
- name: "salesforce__account_field"
alias: "renamed_field"
transform_sql: "cast(renamed_field as string)"
salesforce__contact_pass_through_columns:
- name: "salesforce__contact_field"
alias: "contact_field_x"
salesforce__event_pass_through_columns:
- name: "salesforce__event_field"
transform_sql: "cast(salesforce__event_field as int64)"
salesforce__lead_pass_through_columns:
- name: "salesforce__lead_field"
salesforce__opportunity_pass_through_columns:
- name: "salesforce__opportunity_field"
alias: "opportunity_field_x"
salesforce__opportunity_line_item_pass_through_columns:
- name: "salesforce__opportunity_line_item_field"
alias: "opportunity_line_item_field_x"
- name: "field_name_2"
salesforce__order_pass_through_columns:
- name: "salesforce__order_field"
alias: "order_field_x"
- name: "another_field"
alias: "field_abc"
salesforce__product_2_pass_through_columns:
- name: "salesforce__product_2_field"
alias: "product_2_field_x"
salesforce__task_pass_through_columns:
- name: "salesforce__task_field"
alias: "task_field_x"
salesforce__user_role_pass_through_columns:
- name: "salesforce__user_role_field"
alias: "user_role_field_x"
salesforce__user_pass_through_columns:
- name: "salesforce__user_field"NOTE: If you are creating a passthrough column that applies
transform_sqlto a field already included by default, you must capitalize thenamevalue like such:
salesforce__lead_pass_through_columns:
- name: "Email" # instead of email
alias: "email_domain"
transform_sql: "split(email_domain, '@')[0]"The source tables Fivetran syncs do not include formula fields. If your company uses them, you can generate them by referring to the Salesforce Formula Utils package. To pass through the fields, add the latest version of the package. We recommend confirming your formula field models successfully populate before integrating with the Salesforce package.
Include the following within your dbt_project.yml file:
# Using the opportunity source table as example, update the opportunity variable to reference your newly created model that contains the formula fields:
salesforce_opportunity_identifier: "'my_new_opportunity_formula_table'"
# In addition, add the desired field names as pass through columns
salesforce__opportunity_pass_through_columns:
- name: "salesforce__opportunity_field"
alias: "opportunity_field_x"Fivetran offers the ability for you to orchestrate your dbt project through the Fivetran Transformations for dbt Core™ product. Refer to the linked docs for more information on how to setup your project for orchestration through Fivetran.
This dbt package is dependent on the following dbt packages. For more information on the below packages, refer to the dbt hub site.
If you have any of these dependent packages in your own
packages.ymlI highly recommend you remove them to ensure there are no package version conflicts.
packages:
- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
- package: dbt-labs/dbt_utils
version: [">=1.0.0", "<2.0.0"]
- package: dbt-labs/spark_utils
version: [">=0.3.0", "<0.4.0"]The Fivetran team maintaining this package only maintains the latest version of the package. We highly recommend you stay consistent with the latest version of the package and refer to the CHANGELOG and release notes for more information on changes across versions.
These dbt packages are developed by a small team of analytics engineers at Fivetran. However, the packages are made better by community contributions.
We highly encourage and welcome contributions to this package. Check out this post on the best workflow for contributing to a package.
- If you encounter any questions or want to reach out for help, see the GitHub Issue section to find the right avenue of support for you.
- If you would like to provide feedback to the dbt package team at Fivetran, or would like to request a future dbt package to be developed, then feel free to fill out our Feedback Form.