All Collections
Salesforce CRM integration
SalesWings x Salesforce Sync Overview
SalesWings for Salesforce - Overview of Synchronization Mechanism
SalesWings for Salesforce - Overview of Synchronization Mechanism

Read this article to understand how the data is synchronized and consistent between SalesWings the Salesforce org.

Pauline from SalesWings avatar
Written by Pauline from SalesWings
Updated this week

Table of content:

Introduction

To keep data synchronized and consistent SalesWings Studio makes use of scheduled and asynchronous jobs that run regularly. Knowing how all this works is key to understanding how the Salesforce platform is engaged at any given time.

Turning The Sync On or Off

The synchronization should be turned on or off from the SalesWings Setup page alone. For argument’s sake, although Salesforce gives a possibility to abort both scheduled and async jobs from the Scheduled Jobs and Apex Jobs pages respectively that is not recommended as there might be more than 1 job scheduled or queued at a given time. Turning the sync off from the Setup page will take care of all of them at once.

Synchronization turned off

Synchronization turned on

Sync Commands Via REST API Call

An additional method, via REST API, is provided to turn the sync on or off. It can also be used to return the sync status.

Endpoint

Method

Description

/Sync/v1/GetSyncStatus

GET

By means of a JSON object it returns the status of the sync:

1{ 2 "asyncQueued": {}, 3 "scheduledRunner": {}, 4 "scheduledWatcher": {}, 5 "lastExecution": {} 6}

/Sync/v1/RestartSync

POST

It will turn the sync off and on.

If the sync is detected to be already running the call will return a 412 status code. The restart of the sync can be forced by adding the query parameter force=true.

If the call is successful a the sync status JSON representation is returned.

The Concept

When the synchronization is turned on the following will happen:

  1. a scheduled job named SalesWings Studio : Watcher will be immediately created.

  2. SalesWing Studio : Watcher will execute 1 minute after the synchronization was turned on, and subsequently every hour (this means that 1 scheduled job slot will be permanently occupied by it). Its execution will trigger (a job associated with the class WorkflowSchedulable will appear in the Apex Jobs page) the synchronization cycle made up of different workflow steps.

  3. Each workflow step runs as independent Apex Job associated with a class having SWJob as a prefix.

  4. The last job, named SWJobEnqueuer, wraps up the cycle and schedules the next execution to run after a certain number of minutes, as defined in the Sync Gap (mins.) field in the SW Studio Options Custom Settings. It will scheduled a job named SalesWings Studio : Runner (this requires an additional, but temporary, scheduled job slot).

  5. After the given number of minutes SalesWings Studio : Runner executes and step 3 is repeated.

The Concept Visualized

More on SalesWings Studio : Watcher

This scheduled job is tasked with multiple responsibilities:

  • Kicking off the sync the first time it’s scheduled

  • Deleting any number of SW Apex Job records that exceeds the maximum number as defined in the Apex Jobs Number Threshold field of SW Studio Options Custom Settings.

  • Restarting the sync if, for some reason, it failed to re-enqueue itself.

  • Notifying users if the sync hasn’t run in a certain amount of time as per rules defined by the SW Studio Notification Settings Custom Settings

Keeping Track on the sync

For every synchronization cycle a corresponding SW Apex Job record gets created. The record keeps track of synchronization start and end time as well as of its status. It also provide a text area field in which specific workflow step information are kept and saved in a JSON format.

By accessing the SW Apex Job list view is possible to have an immediate feedback of the synchronization cycles and the status of their completion.

List of SW Apex Job record. Each record represents 1 synchronization cycle

The detail page provides access to the text area field with the step information in their JSON representation.

SW Apex Job Detail page

The Statuses

To the overall synchronization, one of the following statuses can be assigned:

  • Queued: the synchronization will begin shortly.

  • Processing: the synchronization process has started.

  • Failed: the synchronization failed (all the steps registered a Failed status).

  • Partially_Completed: the synchronization completed but some steps either completed partially or outright failed.

  • Completed: the synchronization completed successfully (all the steps registered a Completed status).

To the individual step, one of the following status can be assigned:

  • Queued: the step will soon be processed.

  • Processing: the step is being processed.

  • Failed: the step either encountered an irrecoverable error or all the batches (if applicable) returned errors.

  • Partially_Completed: the step processing completed but some batches (if applicable) failed.

  • Completed: the step completed successfully without reporting any error.

Isolating the Jobs

To better isolate SalesWings jobs from the others running in the organization create a view and use the following filters:

Type

View Name

Filters

Description

Apex Jobs

SW Studio All

  • Apex Class starts with SWJob, SWLog, UpdateToSalesWings

Contains all the jobs created by the solution: batches, queueable, triggers

Apex Jobs

SW Studio Steps

  • Apex Class starts with SWJob

Contains only the jobs that correspond to each synchronization step

Scheduled Jobs

SW Studio

  • Job Name starts with SalesWings Studio

Contains all the scheduled jobs created by the solution

Example of Apex Jobs SW Studio Steps view

Number of SW Apex Job Records

The number of SW Apex Job records kept is determined by the value for Apex Jobs Number Threshold field in the SW Studio Options Custom Settings.

Did this answer your question?