feat: Salesforce - on booking write to fields on person record [CAL-4575]#17477
Conversation
|
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: |
|
|
||
| if ( | ||
| createEventOn === SalesforceRecordEnum.LEAD && | ||
| appOptions.createEventOnLeadCheckForContact && |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
The string length is determined by the custom field in Salesforce
|
|
||
| // Update the person record | ||
| const response = await conn.sobject(personRecordType).update({ | ||
| Id: contactId, |
There was a problem hiding this comment.
The first property in the update object is the WHERE clause.
There was a problem hiding this comment.
Renamed this file
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
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. |
|
|
||
| export enum SalesforceFieldType { | ||
| DATE = "date", | ||
| TEXT = "string", | ||
| } |
There was a problem hiding this comment.
what about other field types?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
booking.creaedAt is already in ISO format
There was a problem hiding this comment.
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.
Udit-takkar
left a comment
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
Do we want to translate these?
E2E results are ready! |
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.
https://www.loom.com/share/06dc1ad0acce47bcb076ddec3bbedb3a
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?