|
| 1 | +--- |
| 2 | +title: RETL Scripts For Importing Salesforce Objects Into Unified Profiles |
| 3 | +hidden: true |
| 4 | +--- |
| 5 | +Unified Profiles users can convert Salesforce objects with US phone number patterns (typically (555) 231-7654) into Segment Unify profiles with E.164 phone number formats (+15552317654) to support Unified Profiles lookup. |
| 6 | + |
| 7 | +Segment created three sample queries for Unified Profiles users to import common Salesforce objects: |
| 8 | +- [Accounts](#accounts) |
| 9 | +- [Contacts](#contacts) |
| 10 | +- [Leads](#leads) |
| 11 | + |
| 12 | +To create a query that selects a different field, replace the `a`, `c`, or `l` with a list of fields to selectively import. |
| 13 | + |
| 14 | +## Accounts |
| 15 | + |
| 16 | +To import Salesforce Accounts into Unified Profiles as Segment Unify profiles, create a RETL mapping with the following format. |
| 17 | + |
| 18 | +Replace `<database_name.account_table>` with your database name and account table, `PHONE` with the name of the column in your warehouse that contains phone numbers, and `BILLING_COUNTRY` with the name of the column in your warehouse that contains the account's billing country. |
| 19 | + |
| 20 | +``` sql |
| 21 | +SELECT |
| 22 | + a.*, |
| 23 | + CASE |
| 24 | + WHEN a.PHONE REGEXP '^(\\([0-9]{3}\\) [0-9]{3}-[0-9]{4})$' AND a.BILLING_COUNTRY = 'US' |
| 25 | + THEN CONCAT('+1', REGEXP_REPLACE(a.PHONE, '[^0-9]','')) |
| 26 | + WHEN a.BILLING_COUNTRY != 'US' |
| 27 | + THEN REGEXP_REPLACE(a.PHONE, '[^0-9]','') |
| 28 | + ELSE a.PHONE |
| 29 | + END as phone, |
| 30 | +FROM |
| 31 | + <database_name.account_table> a |
| 32 | +WHERE |
| 33 | + a.PHONE IS NOT NULL |
| 34 | + AND a.BILLING_COUNTRY IS NOT NULL; |
| 35 | +``` |
| 36 | + |
| 37 | +Salesforce objects have several phone number-related fields. In this example query, the “PHONE” column is the primary contact phone number and what you import as the Profile’s 'phone' trait. The other phone fields for Salesforce Accounts are PersonHomePhone, PersonMobilePhone, & PersonOtherPhone, and could be substituted for "PHONE" in this query. |
| 38 | + |
| 39 | +After running this query, 'phone' would be an Identity used for lookups in Unified Profiles. |
| 40 | + |
| 41 | + |
| 42 | +## Contacts |
| 43 | + |
| 44 | +To import Salesforce Contacts into Unified Profiles as Segment Unify profiles, create a RETL mapping with the following format. |
| 45 | + |
| 46 | +Replace `<database_name.contact_table>` with your database name and account table, `PHONE` with the name of the column in your warehouse that contains phone numbers, and `BILLING_COUNTRY` with the name of the column in your warehouse that contains the contact's billing country. |
| 47 | + |
| 48 | +``` sql |
| 49 | +SELECT |
| 50 | + c.*, |
| 51 | + CASE |
| 52 | + WHEN c.PHONE REGEXP '^(\\([0-9]{3}\\) [0-9]{3}-[0-9]{4})$' AND c.BILLING_COUNTRY = 'US' |
| 53 | + THEN CONCAT('+1', REGEXP_REPLACE(c.PHONE, '[^0-9]','')) |
| 54 | + WHEN c.BILLING_COUNTRY != 'US' |
| 55 | + THEN REGEXP_REPLACE(c.PHONE, '[^0-9]','') |
| 56 | + ELSE c.PHONE |
| 57 | + END as phone, |
| 58 | +FROM |
| 59 | + <database_name.contact_table> c |
| 60 | +WHERE |
| 61 | + c.PHONE IS NOT NULL |
| 62 | + AND c.BILLING_COUNTRY IS NOT NULL; |
| 63 | +``` |
| 64 | + |
| 65 | +Salesforce objects have several phone number-related fields. In this example query, the “PHONE” column is the primary contact phone number and what you import as the Profile’s 'phone' trait. The other phone fields for Salesforce Contacts are HomePhone, MobilePhone, & OtherPhone, and could be substituted for "PHONE" in this query. |
| 66 | + |
| 67 | +After running this query, 'phone' would be an Identity used for lookups in Unified Profiles. |
| 68 | + |
| 69 | +## Leads |
| 70 | + |
| 71 | +To import Salesforce Leads into Unified Profiles as Segment Unify profiles, create a RETL mapping with the following format. |
| 72 | + |
| 73 | +Replace `<database_name.lead_table>` with your database name and lead table, `PHONE` with the name of the column in your warehouse that contains phone numbers, and `BILLING_COUNTRY` with the name of the column in your warehouse that contains the lead's billing country. |
| 74 | + |
| 75 | +``` sql |
| 76 | +SELECT |
| 77 | + l.*, |
| 78 | + CASE |
| 79 | + WHEN l.PHONE REGEXP '^(\\([0-9]{3}\\) [0-9]{3}-[0-9]{4})$' AND l.BILLING_COUNTRY = 'US' |
| 80 | + THEN CONCAT('+1', REGEXP_REPLACE(l.PHONE, '[^0-9]','')) |
| 81 | + WHEN l.BILLING_COUNTRY != 'US' |
| 82 | + THEN REGEXP_REPLACE(l.PHONE, '[^0-9]','') |
| 83 | + ELSE l.PHONE |
| 84 | + END as phone, |
| 85 | +FROM |
| 86 | + <database_name.lead_table> l |
| 87 | +WHERE |
| 88 | + l.PHONE IS NOT NULL |
| 89 | + AND l.BILLING_COUNTRY IS NOT NULL; |
| 90 | +``` |
| 91 | + |
| 92 | +Salesforce objects have several phone number-related fields. In this example query, the “PHONE” column is the primary contact phone number and what you import as the Profile’s 'phone' trait. The other phone fields for Salesforce Leads are HomePhone, MobilePhone, & OtherPhone, and could be substituted for "PHONE" in this query. |
| 93 | + |
| 94 | +After running this query, 'phone' would be an Identity used for lookups in Unified Profiles. |
| 95 | + |
| 96 | +## Troubleshooting |
| 97 | +If these queries don't return phone numbers in E.164 format, examine your existing data and change the REGEX patterns as appropriate. |
| 98 | + |
| 99 | +Because the format in which an international phone number is saved in Salesforce largely depends on how users input them into the system, Salesforce administrators can add form validation methods, like input field validation rules with REGEX functions, to guide users to input phone numbers in specific formats. These form validation methods may impact the format of the phone numbers in your database, and might require you to change the REGEX patterns in the provided queries. |
0 commit comments