feat: Salesforce - Fallback to Lead if Contact Isn't Found For Routing (#20423)
* Add fallback to lead to schema * FE option to fallback to lead owner * Logic to query for contacts and leads for RR skip
This commit is contained in:
1 parent
e67e073f04
commit
b597dad450
4 files changed
+45
No files matched your search
@@ -3044,5 +3044,6 @@
|
||||
"could_not_find_slug_to_publish_org": "Could not find slug to publish the organization",
|
||||
"picklist": "Picklist",
|
||||
"name_or_email": "Name or Email",
|
||||
"salesforce_round_robin_skip_fallback_to_lead_owner": "If no contact is found, fallback to lead owner if it exists",
|
||||
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
|
||||
}
|
||||
@@ -46,6 +46,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
|
||||
const onBookingWriteToRecord = getAppData("onBookingWriteToRecord") ?? false;
|
||||
const onBookingWriteToRecordFields = getAppData("onBookingWriteToRecordFields") ?? {};
|
||||
const ignoreGuests = getAppData("ignoreGuests") ?? false;
|
||||
const roundRobinSkipFallbackToLeadOwner = getAppData("roundRobinSkipFallbackToLeadOwner") ?? false;
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
@@ -522,6 +523,18 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{checkOwnerSelectedOption.value === SalesforceRecordEnum.CONTACT ? (
|
||||
<div className="my-4">
|
||||
<Switch
|
||||
label={t("salesforce_round_robin_skip_fallback_to_lead_owner")}
|
||||
labelOnLeading
|
||||
checked={roundRobinSkipFallbackToLeadOwner}
|
||||
onCheckedChange={(checked) => {
|
||||
setAppData("roundRobinSkipFallbackToLeadOwner", checked);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="my-4">
|
||||
<Switch
|
||||
label={t("salesforce_if_free_email_domain_skip_owner_check")}
|
||||
|
||||
@@ -413,6 +413,36 @@ export default class SalesforceCRMService implements CRM {
|
||||
|
||||
let records: ContactRecord[] = [];
|
||||
|
||||
// This combination is for searching for ownership via contacts
|
||||
if (
|
||||
recordToSearch === SalesforceRecordEnum.CONTACT &&
|
||||
appOptions?.roundRobinSkipFallbackToLeadOwner &&
|
||||
forRoundRobinSkip
|
||||
) {
|
||||
const searchResult = await conn.search(
|
||||
`FIND {${emailArray[0]}} IN EMAIL FIELDS RETURNING Lead(Id, Email, OwnerId, Owner.Email), Contact(Id, Email, OwnerId, Owner.Email)`
|
||||
);
|
||||
|
||||
if (searchResult.searchRecords.length > 0) {
|
||||
// See if a contact was found first
|
||||
const contactQuery = searchResult.searchRecords.filter(
|
||||
(record) => record.attributes?.type === SalesforceRecordEnum.CONTACT
|
||||
);
|
||||
|
||||
if (contactQuery.length > 0) {
|
||||
records = contactQuery as ContactRecord[];
|
||||
} else {
|
||||
// If not fallback to lead
|
||||
const leadQuery = searchResult.searchRecords.filter(
|
||||
(record) => record.attributes?.type === SalesforceRecordEnum.LEAD
|
||||
);
|
||||
if (leadQuery.length > 0) {
|
||||
records = leadQuery as ContactRecord[];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If falling back to contacts, check for the contact before returning the leads or empty array
|
||||
if (
|
||||
appOptions.createEventOn === SalesforceRecordEnum.LEAD &&
|
||||
|
||||
@@ -41,6 +41,7 @@ export const appDataSchema = eventTypeAppCardZod.extend({
|
||||
.default(SalesforceRecordEnum.CONTACT)
|
||||
.optional(),
|
||||
ifFreeEmailDomainSkipOwnerCheck: z.boolean().optional(),
|
||||
roundRobinSkipFallbackToLeadOwner: z.boolean().optional(),
|
||||
skipContactCreation: z.boolean().optional(),
|
||||
createEventOn: z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
|
||||
createNewContactUnderAccount: z.boolean().optional(),
|
||||
|
||||
Reference in new issue
Block a user