connecting-salesforce

Connecting Salesforce

Create a Connected App in Salesforce once, connect it to BlackBox Analytics, then build datasets from the objects available to the connected Salesforce user. BlackBox Analytics imports data but does not update Salesforce records.

Before this: installation, initial setup. After this: datasets and field configuration.


1. Create the Connected App in Salesforce

In Salesforce: Setup → App Manager → New Connected App (or New External Client App on newer orgs).

Setting Value
Connected App Name BlackBox Analytics
API Name BlackBox_Analytics
Contact Email your admin address
Enable OAuth Settings ✅
Callback URL <your public URL>/api/connections/oauth/callback
Selected OAuth Scopes Manage user data via APIs (api), Perform requests at any time (refresh_token, offline_access)
Require Proof Key for Code Exchange (PKCE) ✅ recommended — BlackBox always sends an S256 challenge
Require Secret for Web Server Flow ✅ (recommended)
Require Secret for Refresh Token Flow ✅ (recommended)

The callback URL must match BBA_PUBLIC_URL exactly, including the scheme and any port — for example https://analytics.acme.com/api/connections/oauth/callback. If you change BBA_PUBLIC_URL later, update the Connected App too.

After saving, open Manage Consumer Details and copy the Consumer Key and Consumer Secret. Salesforce can take a few minutes to activate a new Connected App; a client identifier is invalid error usually just means "wait five minutes and try again".

Who the connection runs as

The connection uses the Salesforce identity of the person who completes the sign-in, and it keeps working afterwards through a refresh token. Use a dedicated integration user with:

Optionally restrict the Connected App to that user's profile (Manage → Edit Policies → Permitted Users: Admin approved users).


2. Connect it in BlackBox Analytics

  1. Sign in as an administrator and open Admin → Connections → New connection.
  2. Fill in:
    • Name — how it appears in dataset lists, e.g. "Acme production".
    • Login URL — https://login.salesforce.com for production orgs, https://test.salesforce.com for test orgs, or your My Domain URL (https://acme.my.salesforce.com). My Domain is recommended.
    • Consumer key and Consumer secret from the Connected App.
    • API version — defaults to BBA_SALESFORCE_API_VERSION (v61.0).
  3. Choose Connect. You are sent to Salesforce, sign in, approve access and are returned to the connection page.
  4. Choose Test connection. You should see the org id, org name, username and the round-trip time.

BlackBox Analytics stores the connection details for future refreshes. Keep the installation recovery value described in Installation and operation with your backups; if it changes, reconnect the Salesforce connection.

Disconnect forgets the tokens but keeps the Connected App details, so you can reconnect (or connect as a different user) without retyping them. A connection cannot be deleted while datasets still use it.


3. Build a dataset

Datasets → New dataset → Salesforce (administrators only), then:

  1. Object — the picker lists queryable objects. Sharing rules, history, feed and change-event objects are hidden unless you search for them by name.

  2. Fields — pick what you want to analyse. The picker groups them into standard, custom and related so a 400-field object stays navigable, and the record Id plus a watermark field (SystemModstamp, or LastModifiedDate where that is all the object has) are always included and cannot be unticked, because incremental sync needs both.

    Alongside the object's own fields you can pick fields from any single-target lookup, shown as Site__r.Region__c and labelled Site › Region; those are fetched in the same query, so a shift can carry its site's region and its worker's name without a second dataset. Two deliberate limits keep the list usable: at most 40 fields are offered per relationship, and only the types worth analysing (id, text, picklist, checkbox, date, date/time, numbers, email). Polymorphic lookups such as OwnerId, which can point at a user or a queue, cannot be traversed and are not offered.

  3. Filter (optional) — a SOQL WHERE fragment, e.g. Status__c != 'Draft' AND Site__r.Region__c = 'North'. It is ANDed with the incremental filter on every sync. Only administrators can set it; semicolons and line breaks are rejected.

  4. Primary key — Id. Keep it selected: it is what makes an incremental sync an update rather than a duplicate.

  5. Roll-ups (optional) — numbers computed from child records. See Child roll-ups below.

  6. Sync mode — Incremental for anything that changes over time.

  7. Schedule (optional) — how often the worker refreshes the dataset.

Preview shows twenty typed rows so you can confirm the selection before the first load.

Field types map like this:

Salesforce Stored as
id, string, picklist, multipicklist, text area, phone, url, email, reference, encrypted, time, anytype text
double, currency, percent number
int, long integer
checkbox boolean
date date
date/time datetime (UTC)
address, location, base64, complexvalue, json not importable — compound and binary types have no single column. Pick the components instead (BillingCity, BillingPostalCode, …).

4. How refreshes work

Full load. Every row of the object (subject to your filter) is read in pages, the table is replaced, indexes are rebuilt.

Incremental load. Only records whose SystemModstamp is newer than the last successful sync are read — the query is ordered by SystemModstamp, Id and paged in order. Existing records are updated, new records are added, and records deleted in Salesforce are removed from the dataset. A short overlap with the previous refresh helps include records changed while that refresh was processing.

BlackBox falls back to a full load automatically when:

The reason is recorded in the job log and in the job result, so Admin → Jobs always explains why a run took longer than usual.

After a successful sync the dataset's data version increases, profiling is re-run, insights with "refresh when data changes" are recomputed and (if enabled) a discovery scan is queued.

Child roll-ups

A shift row can carry how many breaks it had, how many minutes of break in total and when the last one started — three ordinary columns computed from the child WFM_Break__c records at sync time. Nothing downstream has to know where they came from: they profile, chart, drive analyses and appear in the public API like any other field.

Adding them. On the Roll-ups step of the dataset wizard, choose a related object (a Salesforce child relationship, shown by its name — "Breaks"), an aggregate and, for everything except Count, the child field to aggregate:

Aggregate Child field Stored as
Count — integer (0 when there are no children)
Distinct count any integer
Total, Average, Lowest, Highest a number field number
Latest date, Earliest date a date or date/time field date / date/time

The name is the column (breaks_minutes_sum) and the label is what people read ("Breaks: total minutes"); both are generated from your choice and can be overwritten. A roll-up name cannot collide with a Salesforce field. An optional filter narrows what is counted (Paid__c = TRUE) — the same rules as the record filter apply, and because SOQL allows only one subquery per relationship, every roll-up on the same related object must use the same filter. Preview shows the computed columns alongside the fields.

Only the record Id is required — roll-ups need it to attach child rows to their parent, and it is always selected anyway.

How they stay current. A full load computes every roll-up in the same query as the parent record (one SOQL subquery per relationship). An incremental sync also asks Salesforce which child records changed since the watermark and re-reads those parents by id, in chunks of 200 — because editing a break does not touch its shift's SystemModstamp, so the parent would otherwise never be re-read. The job result reports how many parents were refreshed that way.

Three limits worth knowing:

Roll-ups are columns, so they are chosen when the dataset is created: to add or drop one afterwards, create the dataset again. Whenever the roll-up set does change, the next sync is a full reload — the existing rows have no value for a new roll-up to fill in.

Limits and etiquette


5. Troubleshooting

Symptom Cause and fix
redirect_uri_mismatch The Connected App callback URL does not match <BBA_PUBLIC_URL>/api/connections/oauth/callback exactly.
client identifier is invalid Wrong consumer key, or the Connected App is still propagating (wait ~5 minutes).
The connection page shows invalid_state The sign-in link expired (ten minutes) or was reused. Start again from Connect.
Salesforce rejected the session — reconnect the connection The refresh token was revoked in Salesforce (Setup → Connected Apps OAuth Usage), the integration user was deactivated, or BBA_SECRET_KEY changed. Reconnect.
A sync suddenly reloads everything Expected after a field change, a 30-day gap or a restore — the job log names the reason.
Row counts are lower than in Salesforce Sharing or field access on the connected user, or a WHERE filter on the dataset.
... is a address field, which cannot be imported Compound fields have no single column; select the component fields instead.
Sync fails with The filter may not contain semicolons or line breaks Clean up the dataset's WHERE fragment.