Accelerator Salesforce Party Event Listener - Implementation Template

(0 reviews)

Prerequisites

This implementation template has the following dependencies:

  • Anypoint MQ Destinations
  • Salesforce Platform Events
  • Salesforce Apex Triggers

Please review the use cases described on the MuleSoft Accelerators solution pages for more information about dependencies on other APIs and services.

Anypoint MQ destinations

In addition to the Anypoint MQ client application credentials, the following destinations must be created and made accessible to this API:

  1. accel-partyrole-update-exchange
  2. accel-partyrole-update-dl-queue
  3. accel-address-update-exchange
  4. accel-address-update-dl-queue
  5. accel-party-update-exchange
  6. accel-party-update-dl-queue
  7. accel-lead-update-exchange
  8. accel-lead-update-dl-queue
  9. accel-opportunity-update-exchange
  10. accel-opportunity-update-dl-queue

Salesforce Platform Events

This implementation requires creation of Platform Events in Salesforce. To create a Platform event Object following the below steps:

  1. Login to Salesforce.
  2. Click Setup to search for Platform Events in Quick Find Box. Platform Events Page under Integrations section appears with list of available Platform Events.
  3. Click New Platform Event button to create an Object and enter Platform Information Details fields like Label, Plural Label and Object. Click Save.
  4. Enter Custom Fields & RelationShips to create an Event with specific defintions.

Platform Event Definition for Account PlatformEvent

Create a Platform Event with Label as AccountPlatformEvent, Object Name as Account and Custom Fields & RelationShips as per below table. These Custom fields can also be created via Apex script - instructions are included in the "Create Custom Fields via Apex script" section, below.

Field LabelAPI NameData Type
AccountNumberAccountNumber__cText(80)
BillingCityBillingCity__cText(80)
BillingCountryBillingCountry__cText(80)
BillingGeocodeAccuracyBillingGeocodeAccuracy__cText(18)
BillingLatitudeBillingLatitude__cText(80)
BillingLongitudeBillingLongitude__cText(80)
BillingPostalCodeBillingPostalCode__cText(80)
BillingStateBillingState__cText(80)
BillingStreetBillingStreet__cText(80)
CreatedDateCreatedDate__cDate/Time
FaxFax__cText(80)
FirstNameFirstName__cText(80)
Global_BillingAddress_IdGlobal_BillingAddress_Id__cText(36)
Global_Customer_IdGlobal_Customer_Id__cText(36)
Global_EmailAddress_IdGlobal_EmailAddress_Id__cText(36)
Global_FaxNumber_IdGlobal_FaxNumber_Id__cText(36)
Global_MailingAddress_IdGlobal_MailingAddress_Id__cText(36)
Global_MobileNumber_IdGlobal_MobileNumber_Id__cText(36)
Global_PhoneNumber_IdGlobal_PhoneNumber_Id__cText(36)
Global_ShippingAddress_IdGlobal_ShippingAddress_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
IsPersonAccountIsPersonAccount__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
LastNameLastName__cText(80)
NameName__cText(80)
PersonEmailPersonEmail__cText(80)
PersonMailingCityPersonMailingCity__cText(80)
PersonMailingCountryPersonMailingCountry__cText(80)
PersonMailingGeocodeAccuracyPersonMailingGeocodeAccuracy__cText(18)
PersonMailingLatitudePersonMailingLatitude__cText(80)
PersonMailingLongitudePersonMailingLongitude__cText(80)
PersonMailingPostalCodePersonMailingPostalCode__cText(80)
PersonMailingStatePersonMailingState__cText(80)
PersonMailingStreetPersonMailingStreet__cText(80)
PersonMobilePhonePersonMobilePhone__cText(80)
PhonePhone__cText(80)
ShippingCityShippingCity__cText(80)
ShippingCountryShippingCountry__cText(80)
ShippingGeocodeAccuracyShippingGeocodeAccuracy__cText(18)
ShippingLatitudeShippingLatitude__cText(80)
ShippingLongitudeShippingLongitude__cText(80)
ShippingPostalCodeShippingPostalCode__cText(80)
ShippingStateShippingState__cText(80)
ShippingStreetShippingStreet__cText(80)

Platform Event Definition for Account Address PlatformEvent

Create a Platform Event with Label as AccountAddressPlatformEvent, Object Name as AccountAddresses and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
BillingCityBillingCity__cText(80)
BillingCountryBillingCountry__cText(80)
BillingGeocodeAccuracyBillingGeocodeAccuracy__cText(10)
BillingLatitudeBillingLatitude__cText(10)
BillingLongitudeBillingLongitude__cText(10)
BillingPostalCodeBillingPostalCode__cText(10)
BillingStateBillingState__cText(80)
BillingStreetBillingStreet__cText(80)
Global_BillingAddress_IdGlobal_BillingAddress_Id__cText(36)
Global_MailingAddress_IdGlobal_MailingAddress_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
PersonMailingCityPersonMailingCity__cText(80)
PersonMailingCountryPersonMailingCountry__cText(80)
PersonMailingGeocodeAccuracyPersonMailingGeocodeAccuracy__cText(10)
PersonMailingLatitudePersonMailingLatitude__cText(10)
PersonMailingLongitudePersonMailingLongitude__cText(10)
PersonMailingPostalCodePersonMailingPostalCode__cText(10)
PersonMailingStatePersonMailingState__cText(80)
PersonMailingStreetPersonMailingStreet__cText(80)

Platform Event Definition for Contact PlatformEvent

Create a Platform Event with Label as ContactPlatformEvent, API Name as Contact and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
BirthdateBirthdate__cDate
CreatedDateCreatedDate__cDate/Time
EmailEmail__cText(80)
FirstNameFirstName__cText(80)
Global_EmailAddress_IdGlobal_EmailAddress_Id__cText(36)
Global_Individual_IdGlobal_Individual_Id__cText(36)
Global_PhoneNumber_IdGlobal_PhoneNumber_Id__cText(36)
Global_PostalAddress_IdGlobal_PostalAddress_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
LastNameLastName__cText(80)
MailingCityMailingCity__cText(80)
MailingPostalCodeMailingPostalCode__cText(36)
MailingStateMailingState__cText(36)
MailingStreetMailingStreet__cText(255)
NameName__cText(80)
PhonePhone__cText(80)
SalutationSalutation__cText(80)

Platform Event Definition for Household PlatformEvent

Create a Platform Event with Label as HouseholdPlatformEvent, Object Name as Household and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
CreatedDateCreatedDate__cDate/Time
Global_Party_IdGlobal_Party_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
IsPersonAccountIsPersonAccount__cCheckbox
LastModifiedByIdLastModifiedById__cText(36)
LastModifiedDateLastModifiedDate__cDate/Time
NameName__cText(80)
RecordTypeIdRecordTypeId__cText(36)

Platform Event Definition for Opportunity PlatformEvent

Create a Platform Event with Label as OpportunityPlatformEvent, Object Name as Opportunity and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
AccountIdAccountId__cText(36)
Ach_Transfer_Auth_Document_IdAch_Transfer_Auth_Document_Id__cText(36)
Asset_Transfer_Auth_Document_IdAsset_Transfer_Auth_Document_Id__cText(36)
CloseDateCloseDate__cDate/Time
CreatedDateCreatedDate__cDate/Time
Document_Signatures_ReceivedDocument_Signatures_Received__cCheckbox
IdId__cText(18)
IsClosedIsClosed__cCheckbox
IsDeletedIsDeleted__cCheckbox
IsWonIsWon__cCheckbox
KYC_CompletedKYC_Completed__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
NameName__cText(80)
StageNameStageName__cText(80)
TypeType__cText(80)

Platform Event Definition for Lead PlatformEvent

Create a Platform Event with Label as LeadPlatformEvent, Object Name as Lead and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
CityCity__cText(80)
ConvertedAccountIdConvertedAccountId__cText(36)
ConvertedDateConvertedDate__cDate
CountryCountry__cText(80)
CreatedDateCreatedDate__cDate/Time
DescriptionDescription__cText(255)
EmailEmail__cText(80)
FirstNameFirstName__cText(80)
IdId__cText(36)
IsConvertedIsConverted__cCheckbox
IsDeletedIsDeleted__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
LastNameLastName__cText(80)
LeadSourceLeadSource__cText(255)
NameName__cText(80)
PhonePhone__cText(80)
PostalCodePostalCode__cText(10)
SalutationSalutation__cText(80)
StateState__cText(80)
StatusStatus__cText(80)
StreetStreet__cText(255)

Create Custom Fields via Apex script

An Apex class called CustomFieldUtility can be used to create custom fields programmatically. The source for this class can be found in the Common Resources project. Download this project and follow the steps below.

  1. Click on Salesforce Setup icon and select Developer Console to open a new console window
  2. Go to File -> New -> Apex class and create a new class named CustomFieldUtility
  3. Copy the code from accelerator-common-resources/salesforce/CustomFieldUtility.apxc to the script editor
  4. Select the File -> Save menu option to compile and save the class
  5. Select Debug -> Open Execute Anonymous Window
  6. Copy and paste the contents of accelerator-common-resources/salesforce/CreatePlatformEventsCustomFields.txt into the window.
  7. Enable the Open Log option and click the Execute button.

Once the script completes, select the Debug Only filter option to show just the results of each create request. Verify that all fields have been successfully created.

Note: Do not execute all the content in the CreatePlatformEventsCustomFields.txt file at once as the console might throw a timeout error. Instead execute it in batches.

Salesforce Apex Triggers

This implementation requires creation of Apex Triggers for the Platform Events to be generated on changes to records in Salesforce.

Salesforce ObjectApex script locationTrigger name
Account/src/test/resources/scripts/accounts-event-publisher.apxtAccountEventsPub
Account/src/test/resources/scripts/account-addresses-event-publisher.apxtAccountAddressEventsPub
Account/src/test/resources/scripts/households-event-publisher.apxtHouseholdEventsPub
Contact/src/test/resources/scripts/contacts-event-publisher.apxtContactEventsPub
Opportunity/src/test/resources/scripts/opportunities-event-publisher.apxtOpportunityEventsPub
Lead/src/test/resources/scripts/leads-event-publisher.apxtLeadEventsPub

Follow the below steps to create the Apex Triggers

  1. Login to Salesforce.
  2. Click Setup to search for Object Manager in Quick Find Box.
  3. Search for the Salesforce Object. A page appears with Details of the Object.
  4. Click Triggers unders the Details section to see list of available triggers on the Object. Click New.
  5. Copy the Script from the location specified in the above table .
  6. Obtain the LastModifiedById and RecordTypeId (if it exists) by running the queries mentioned in the trigger from Developer Console.
  7. Replace the values in the script
  8. Click Save and ensure isActive checkbox is ticked.
  9. Repeat the steps for all the Salesforce objects in the above table

Next steps

The Deployment tab provides instructions on how to properly configure the application for running locally from Studio or deploying to CloudHub.


Reviews

TypeTemplate
OrganizationMuleSoft
Published by
MuleSoft Solutions
Published onNov 8, 2023
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0