Docs

Salesforce

Connect Salesforce by signing in: referred people appear with the partner who sent them, and a won opportunity pays that partner on its amount.

The Salesforce connection works in both directions:

  • To Salesforce: each person a partner refers is matched by email. The contacts with that email get the field Affiligato partner set to the partner’s name and id; with no contact, the open leads with that email do; with neither, Affiligato creates a lead.
  • From Salesforce: when an opportunity is won and one of its people is a person Affiligato sent, the partner who referred that person earns commission on the opportunity’s amount, through your commission rules.

With Salesforce connected, you do not record those payments by hand. See Quotes and invoices for the rest of the setup.

Connect

Connect in the dashboard, so the grant goes from Salesforce to Affiligato and never passes through an AI agent. An agent can call get_integrations to see whether Salesforce is connected, and why a broken connection stopped.

  1. Install the Affiligato package

    A Salesforce admin opens the install link on the Salesforce panel (Settings → Connect → Salesforce) and installs the package in your org. It carries Affiligato’s app, which Salesforce needs installed before anyone in your org can approve it.

  2. Connect Salesforce

    Choose Connect Salesforce, sign in to Salesforce as an admin and choose Allow. Salesforce sends you back to the Connect page.

Connecting asks Salesforce for API access and for access while you are away (the scopes api and refresh_token). Affiligato then:

  • reads your org’s corporate currency, and whether your opportunities carry their own currency;
  • creates the text field Affiligato partner (Affiligato_Partner__c) on leads and on contacts, unless it exists;
  • creates the permission set Affiligato, with read and edit access to both fields, and assigns it to the user who connected.

It keeps Salesforce’s tokens encrypted. If your user may not add fields or permission sets, nothing is kept, the access is revoked, and the panel asks you to connect again as an admin.

What goes to Salesforce

  • While Salesforce is connected, a person is sent when they become a referral and when their customer record changes.
  • A contact or an open lead with the same email has Affiligato partner set to the partner’s name followed by their id in brackets. A new lead has the email as its last name and [not provided] as its company, which Salesforce requires, so edit both when you know them.
  • People are sent in batches, about once a minute. A batch Salesforce does not accept is tried again later, up to eight times.
  • People referred before you connected are not sent when you connect.
  • Sample partners and demo programs are never sent.

Won opportunities

About once a minute, Affiligato reads the opportunities that changed since its last read, starting from the moment you connected.

  • An opportunity counts as won when Salesforce marks it won: a closed stage of type won, whatever its name.
  • It pays only when one of its people is a person Affiligato sent to Salesforce: its contact, a contact in its contact roles, or a lead Affiligato sent that was converted into that contact or into this opportunity. The partner who referred that person earns. An opportunity with no such person is left alone.
  • The sale is the opportunity’s amount, in its own currency when your org has multiple currencies, else in your corporate currency, dated its close date.
  • Each opportunity is credited once. Its transaction id is salesforce: followed by the opportunity id.

Lost opportunities

  • An open or lost opportunity that was never credited is left alone.
  • A credited opportunity that is no longer won has its commission reversed, as a refund of the whole amount. A commission already paid out is taken back from the partner’s next payout.

When the connection breaks

Salesforce’s access tokens expire; Affiligato renews them with the refresh token, one renewal at a time. When Salesforce refuses the refresh token, because the access was revoked or sat unused past your org’s limit, Affiligato stops. The Salesforce panel says Salesforce refused Affiligato’s access. Connect again.

  • People that were waiting to be sent are kept, and go out once you connect again.
  • Affiligato keeps its place in the opportunities, so those that changed while the connection was broken are read after you connect again.

When your org is over its daily API limit, Affiligato stops and continues from the same place on its next run.

Disconnect

Disconnect on the Salesforce panel revokes Affiligato’s access in Salesforce and forgets the tokens. The field, the permission set, the leads and the contacts stay in Salesforce.