Skip to content

feat: Salesforce - on booking write to fields on person record [CAL-4575]#17477

Merged
Udit-takkar merged 12 commits into
mainfrom
salesforce-write-to-person-record
Nov 6, 2024
Merged

feat: Salesforce - on booking write to fields on person record [CAL-4575]#17477
Udit-takkar merged 12 commits into
mainfrom
salesforce-write-to-person-record

Conversation

@joeauyeung
Copy link
Copy Markdown
Contributor

@joeauyeung joeauyeung commented Nov 5, 2024

What does this PR do?

This PR introduces the ability to write to custom fields on a person record (lead, contact, account) in Salesforce when a booking is created. There are currently two data types we handle, text and dates.

  • Fixes #XXXX (GitHub issue number)
  • Fixes CAL-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

https://www.loom.com/share/06dc1ad0acce47bcb076ddec3bbedb3a

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Install Salesforce on an event type
  • Enable "On booking, write to a custom field on the attendee Contact record" on the Salesforce options
  • Add an entry to write the booking date on a date field in Salesforce
  • Add an entry to write text to a text field in Salesforce
  • Create a booking
  • The values should be written on those fields

@dosubot dosubot Bot added crm-apps area: crm apps, salesforce, hubspot, close.com, sendgrid ✨ feature New feature or request labels Nov 5, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 5, 2024

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Salesforce - on booking write to fields on person record". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit


if (
createEventOn === SalesforceRecordEnum.LEAD &&
appOptions.createEventOnLeadCheckForContact &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option allows us to write to either a lead or a contact. So we need to determine what record to query.

if (contactSearch && contactSearch.records.length > 0)
if (contactSearch && contactSearch.records.length > 0) {
records = contactSearch.records as ContactRecord[];
this.setFallbackToContact(true);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're falling back to a contact, let's store that as a variable so in other methods, we know to query the contact objects.


if (fieldSet.has(field.name)) {
foundFields.push(field.name);
foundFields.push(field);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning just the field names, we're returning the whole field object.

// Search the fields and ensure 1. they exist 2. they're the right type
const fieldsToWriteOn = Object.keys(onBookingWriteToRecordFields);

const existingFields = await this.ensureFieldsExistOnObject(fieldsToWriteOn, personRecordType);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Determine that the fields exist on the record or else it would throw an error.

// Determine if the field to write on matches the field type
if (fieldToWriteOn.fieldType === salesforceField.type) {
if (salesforceField.type === SalesforceFieldType.TEXT) {
const stringToWrite = fieldToWriteOn.value.substring(0, salesforceField.length);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string length is determined by the custom field in Salesforce


// Update the person record
const response = await conn.sobject(personRecordType).update({
Id: contactId,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first property in the update object is the WHERE clause.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this file

@joeauyeung joeauyeung changed the title Salesforce - on booking write to fields on person record feat: Salesforce - on booking write to fields on person record Nov 5, 2024
@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2024 8:07am
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2024 8:07am

@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented Nov 5, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (11/05/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add ready-for-e2e label" took an action on this PR • (11/06/24)

1 label was added to this PR based on Keith Williams's automation.

Comment on lines +11 to +15

export enum SalesforceFieldType {
DATE = "date",
TEXT = "string",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about other field types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add those later. I want to get this feature out now as a customer has been waiting.

return;
}

writeOnRecordBody[salesforceField.name] = new Date(booking.createdAt).toISOString();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

booking.creaedAt is already in ISO format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we left it as is? Right now it's typed as a Date but when calling .toISOString() it converts it to type string which the function getDateFieldValue expects as a return value.

Copy link
Copy Markdown
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally a function in a class should be responsible for one thing.

I have refactored the CRM service function that you created here #17481 to make it more readable, easier to test and maintainable

const [writeToPersonObjectFieldType, setWriteToPersonObjectFieldType] = useState(fieldTypeOptions[0]);

const whenToWriteToRecordOptions = [
{ label: "On every booking", value: WhenToWriteToRecord.EVERY_BOOKING },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to translate these?

@joeauyeung joeauyeung changed the title feat: Salesforce - on booking write to fields on person record feat: Salesforce - on booking write to fields on person record [CAL-4575] Nov 5, 2024
@linear
Copy link
Copy Markdown

linear Bot commented Nov 5, 2024

Udit-takkar
Udit-takkar previously approved these changes Nov 6, 2024
Copy link
Copy Markdown
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 6, 2024

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consumer core area: core, team members only crm-apps area: crm apps, salesforce, hubspot, close.com, sendgrid ✨ feature New feature or request ready-for-e2e

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants