See what changes triggered a Salesforce update subscription

Aug 5th, 2021view comments

There is a new changeList field in update subscription payloads for Salesforce. The field will list the fields that changed in the update and their values before and after the update.

For example, if you have the following subscription to Opportunity updates

subscription OpportunitySubscription {
  salesforce {
    opportunityUpdated {
      opportunity {
        id
        stageName
      }
      oldOpportunity {
        id
        stageName
      }
      changeList {
        field
        newValue
        oldValue
        fieldName
      }
    }
  }
}

and the stage for the opportunity is updated, you'll see a list of all of the changed fields on the Opportunity

{
  "data": {
    "salesforce": {
      "opportunityUpdated": {
        "changeList": [
          {
            "field": "PROBABILITY",
            "newValue": 90,
            "oldValue": 75,
            "fieldName": "probability"
          },
          {
            "field": "STAGE_NAME",
            "newValue": "Negotiation/Review",
            "oldValue": "Proposal/Price Quote",
            "fieldName": "stageName"
          },        
          {
            "field": "LAST_STAGE_CHANGE_DATE",
            "newValue": "2021-08-05T19:06:58.000+0000",
            "oldValue": "2021-08-05T19:00:41.000+0000",
            "fieldName": "lastStageChangeDate"
          },
          {
            "field": "SYSTEM_MODSTAMP",
            "newValue": "2021-08-05T19:06:58.000+0000",
            "oldValue": "2021-08-05T19:00:41.000+0000",
            "fieldName": "systemModstamp"
          },
          {
            "field": "LAST_MODIFIED_DATE",
            "newValue": "2021-08-05T19:06:58.000+0000",
            "oldValue": "2021-08-05T19:00:41.000+0000",
            "fieldName": "lastModifiedDate"
          }
        ],
        "opportunity": {
          "id": "0062100000DxkgLAAR",
          "stageName": "Negotiation/Review"
        },
        "oldOpportunity": {
          "id": "0062100000DxkgLAAR",
          "stageName": "Proposal/Price Quote"
        }
      }
    }
  }
}

Did you know that the probability automatically updates with the stage? I didn't, but now I do!

Custom fields that have not been mapped by OneGraph will have the special ANY_CUSTOM_FIELD enum value as their field, and the fieldName will match the name you see in the customFields field for the object. Go to the Architect tab of the OneGraph dashboard to set up a custom schema for your Salesforce instance that maps all custom fields to fields in the schema.

Read more about GraphQL subscriptions and Salesforce subscriptions in the docs.