View for getting the connection between Salesforce accountid
to the relevant user email
.
-- CREATE VIEW salesforce_account_to_email AS
WITH email_accountid AS (
SELECT
DISTINCT sfc.email,
sfc.accountid
FROM
public.salesforce_contact sfc
UNION -- Leads and Contacts are combined by UNION because they are mutually exclusive groups of individuals
SELECT
DISTINCT sfl.email,
sfl.convertedaccountid
FROM
public.salesforce_lead sfl
)
SELECT
DISTINCT eaid.email,
eaid.accountid,
sfa.name account_name
FROM
email_accountid eaid
LEFT JOIN public.salesforce_account sfa ON eaid.accountid = sfa.id
Column | Description |
---|---|
email |
Opportunity Email |
accountid |
Salesforce Account ID |
account_name |
Account Name |