# Salesforce Data 360 integration

Google Cloud Cortex Framework lets you reference **Salesforce Data 360** (formerly
Salesforce Data Cloud) objects with zero data copy by using
[BigQuery sharing](https://docs.cloud.google.com/bigquery/docs/analytics-hub-introduction.md.txt).
When you subscribe to a Salesforce Data 360 data share as a linked dataset in
BigQuery, you can register that dataset as an `analytics_hub` catalog
module in `config/config.yaml` and build custom downstream data products
without maintaining extraction pipelines.

## Compare replication and Data 360 sharing

Cortex Framework supports both physical SObject replication and
zero-copy Data 360 sharing, and you can combine both patterns in a single
deployment. Compare the two approaches in the following table:

| Dimension | Salesforce physical replication | Salesforce Data 360 zero-copy sharing |
| Primary source | Salesforce Sales Cloud and Service Cloud SObjects | Salesforce Data 360 Data Model Objects (DMOs), Data Lake Objects (DLOs), and Calculated Insights |
| Ingestion mechanism | Physical replication into BigQuery using [BigQuery Data Transfer Service](https://docs.cloud.google.com/bigquery/docs/salesforce-transfer-intro.md.txt) or CDC connectors | Zero-copy linked dataset subscribed through [BigQuery sharing](https://docs.cloud.google.com/bigquery/docs/analytics-hub-introduction.md.txt) |
| Cortex Framework module type | Foundation module (`modulePath: cortex.sfdc.foundations.sfdc`) feeding prebuilt `cortex.sfdc.products.*` data products | Catalog module (`type: analytics_hub`) feeding custom data products in your namespace |
| Best fit | Deploying prebuilt Sales Cloud and Service Cloud data products with full control over BigQuery partitioning, clustering, and retention | Enriching custom data products with unified customer profiles, segments, or engagement signals already harmonized in Data 360 |
|---|---|---|

For physical SObject replication instructions, see
[Salesforce integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/salesforce.md.txt).

## Before you begin

Before you register a Salesforce Data 360 catalog in
Cortex Framework, complete the following steps:

1. Enable the BigQuery (`bigquery.googleapis.com`), BigQuery sharing (`analyticshub.googleapis.com`), and Dataform (`dataform.googleapis.com`) APIs in your Google Cloud projects.
2. In Salesforce Data 360, create and publish a data share targeting BigQuery that includes the DMOs, DLOs, or Calculated Insights you plan to query.
3. In Google Cloud, [subscribe to the listing in BigQuery sharing](https://docs.cloud.google.com/bigquery/docs/analytics-hub-view-subscribe-listings.md.txt) to create a read-only linked dataset in your project. Verify that the linked dataset resides in a region compatible with your target `data.bigQueryLocation`.
4. Grant the required Identity and Access Management (IAM) roles:
   - **Subscription administrator** : Analytics Hub Subscriber (`roles/analyticshub.subscriber`) to create and manage the linked dataset.
   - **CLI build principal** (`uv run cortex-build`): BigQuery Data Viewer (`roles/bigquery.dataViewer`) on the linked dataset, BigQuery Job User (`roles/bigquery.jobUser`) on `buildProjectId`, and Analytics Hub Subscription Owner (`roles/analyticshub.subscriptionOwner`)---or a custom role that includes `analyticshub.subscriptions.list`---on the consumer project for subscription health checks and automatic listing discovery. If you read private listing metadata, also grant Analytics Hub Viewer (`roles/analyticshub.viewer`) on the listing or data exchange. `roles/analyticshub.viewer` alone excludes `analyticshub.subscriptions.list`, so granting only `roles/analyticshub.viewer` on the consumer project causes subscription checks and subscription-based listing discovery to be skipped with a warning.
   - **Dataform execution service account** : BigQuery Data Viewer (`roles/bigquery.dataViewer`) on the linked dataset, BigQuery Data Editor (`roles/bigquery.dataEditor`) on your writable target dataset, and BigQuery Job User (`roles/bigquery.jobUser`) on the execution project.
5. Record the exact table or view names exposed inside the linked BigQuery dataset so you can declare them in `inlineTableSettings.tables` (or under `inlineTableSettings.variants`).

## Register a Salesforce Data 360 catalog

In `config/config.yaml`, register the subscribed linked dataset under
`data.modules.catalogs` with `type: analytics_hub`. You must explicitly list the
shared tables or views to expose in `inlineTableSettings.tables` (or optional
variant-specific lists under `inlineTableSettings.variants`, paired with
`variants` on the catalog entry); during `uv run cortex-build`,
`AnalyticsHubCatalogBuilder` generates Dataform source declarations
exclusively for that allowlist without copying data.

```yaml
buildEnvironment:
  buildProjectId: BUILD_PROJECT_ID

data:
  bigQueryLocation: US
  namespaces:
    - name: cortex
    - name: custom
      path: ../src/data_modules/custom
  datasets:
    - id: custom_products
      projectId: TARGET_PROJECT_ID
      datasetId: custom_customer_360

  modules:
    catalogs:
      # BigQuery Sharing (Analytics Hub) linked dataset catalog.
      - id: sfdc_data_cloud_catalog
        type: analytics_hub
        enabled: true
        bindsNamespaces:
          - sfdc_data_cloud
        connectionSettings:
          projectId: LINKED_DATASET_PROJECT_ID
          datasetId: LINKED_DATASET_ID
          location: US
        # Required allowlist of shared tables or views in the linked dataset.
        inlineTableSettings:
          tables:
            - UnifiedIndividual__dlm
            - UnifiedAccount__dlm

    products:
      # Custom data product referencing shared Data 360 tables.
      - moduleId: customer_360_summary
        modulePath: custom.sfdc.products.customer_360_summary
        dataTargetId: custom_products
        dependencyBindings:
          unifiedIndividual: sfdc_data_cloud_catalog.UnifiedIndividual__dlm
          dataCloudCatalog: sfdc_data_cloud_catalog
```

Replace the following:

- `BUILD_PROJECT_ID`: the Google Cloud project ID used for build validation, for example: `my-build-project`.
- `TARGET_PROJECT_ID`: the Google Cloud project ID where custom downstream data products are materialized, for example: `my-target-project`.
- `LINKED_DATASET_PROJECT_ID`: the Google Cloud project ID that hosts the subscribed BigQuery sharing linked dataset, for example: `my-subscriber-project`.
- `LINKED_DATASET_ID`: the BigQuery dataset ID of the linked dataset created from the Salesforce Data 360 share, for example: `sfdc_data_360_linked`.

Optionally, you can specify `connectionSettings.listingId` for governance
traceability as a canonical resource path, a full listing URL
(`https://analyticshub.googleapis.com/v1/...`), or a four-part dot-separated ID
(when omitted, Cortex Framework auto-discovers the source listing
from subscription or dataset metadata):

    projects/PROVIDER_PROJECT/locations/LOCATION/dataExchanges/EXCHANGE_ID/listings/LISTING_ID
    PROVIDER_PROJECT.LOCATION.EXCHANGE_ID.LISTING_ID

Replace the following:

- `PROVIDER_PROJECT`: the publisher Google Cloud project ID hosting the data exchange, for example: `sfdc-data-cloud-provider`.
- `LOCATION`: the BigQuery location of the data exchange, for example: `US`.
- `EXCHANGE_ID`: the BigQuery sharing data exchange ID, for example: `sfdc_data_360_exchange`.
- `LISTING_ID`: the BigQuery sharing listing ID, for example: `unified_customer_360`.

For full field specifications, see
[Data: Modules: Catalogs](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#data_modules_catalogs).

## Reference shared tables in custom data products

Custom data products can bind to an `analytics_hub` catalog in
`dependencyBindings` by using either of two binding formats:

- **Two-part table binding (`<catalog_id>.<table_name>`)** : Binds a logical input directly to a single shared table declared in `inlineTableSettings.tables` (for example, `sfdc_data_cloud_catalog.UnifiedIndividual__dlm`).
- **One-part catalog binding (`<catalog_id>`)** : Binds a logical input to the catalog module as a whole when your module manifest declares required table names under the namespace listed in `bindsNamespaces`.

Inside your custom Dataform `.js` model definition, reference the
resolved source dataset with `ctx.ref()` and publish the model with
`publisher.publish(...)`:

```javascript
// ___MODULE_CONTEXT___
// ___TABLE_CONFIG___

const publish_config = require("includes/publish_config.js");
const publisher = require("includes/publisher.js");

const moduleConfig = config.product[moduleContext.moduleId];
const individualSource = moduleConfig.sources.unifiedIndividual;

const materializationType = tableConfig.materializationType || "table";
const publishConfig = publish_config.getPublishConfig(
  materializationType,
  tableConfig,
  moduleConfig
);

publisher.publish(moduleContext.moduleId + "_" + tableConfig.tableName, publishConfig).query(
  (ctx) => `
    SELECT
      ssot__Id__c AS unified_individual_id,
      ssot__FirstName__c AS first_name,
      ssot__LastName__c AS last_name,
      CURRENT_TIMESTAMP() AS bq_loaded_at
    FROM ${ctx.ref(
      individualSource.projectId,
      individualSource.datasetId,
      "UnifiedIndividual__dlm"
    )}
  `
);
```

> [!NOTE]
> **Note:** Linked datasets created through BigQuery sharing are read-only in the subscriber project. Materialize your custom Cortex Framework data products into a standard writable BigQuery target dataset.

To validate and deploy your catalog and custom data product definitions, run:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-build-and-deploy --config $CORTEX_CONFIG_FILE
```

Then trigger the Dataform pipeline as described in
[Post-deployment steps](https://docs.cloud.google.com/cortex/docs/post-deployment-steps.md.txt). For details on
pre-flight link-state checks, subscription health warnings, cross-region dataset
replicas, and local metadata caching (`uv run cortex-metadata fetch`), see
[BigQuery sharing integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt#preflight-validation).

## What's next

- Replicate operational Sales Cloud and Service Cloud tables in [Salesforce integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/salesforce.md.txt).
- Blend commercial, weather, or cross-organization listings in [BigQuery sharing integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt).
- Review catalog configuration parameters in [Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#data_modules_catalogs).
- Build custom modules on shared catalogs in [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt).