1

I have a custom trigger that fires on an OpportunityChangeEvent:

trigger EXAMPLE_CREATE on OpportunityChangeEvent(after insert) {
  // Get the change event’s product ID for added and updated products

  for (OpportunityChangeEvent event : Trigger.new) {
    EventBus.ChangeEventHeader header = event.ChangeEventHeader;

    if ((header.changetype != 'DELETE')) {
      // For update operations, iterate over the list of changed fields
      for (String field : header.changedFields) {
        if(field == 'StageName') {
          if (event.get(field) == 'Digital-Installing') {
            List<String> accountNumber = header.getRecordIds();
            String accNum = accountNumber.get(0);
            ...

This trigger enqueues a job, which is represented as a custom class:

Id getSiteJobId = System.enqueueJob(
                  new EXAMPLE_API_SITE(
                    'site',
                    'GET',
                    siteMap,
                    woMap,
                    '?site_id=' +
                    ss.Account_Number__c +
                    '&name=' +
                    EncodingUtil.urlEncode(accName, 'UTF-8')
                  )
                );

The custom class makes http callouts to an API that I control:

HttpResponse response = new HTTP().send(request);

Recently the authorization on that account changed in the API and the requests started failing; When the EXAMPLE_API_SITE class received the response, it threw Apex runtime errors as it tried to set the response to a variable of the wrong type.

Since then I have updated the authorization on the API, which solves the problem in the sandbox environment. Now in production, no jobs are queued from the OpportunityChangeEvent at all. I have a trace on the AutomatedProcess entity, which has not produced logs in production, but does so reliably in the sandbox.

Jobs appear to have stopped firing in production at roughly the same time as the authorization issue caused runtime errors. When I stood up the sandbox environment, it also would not queue jobs in this way, but started doing so ~24 hours later.

Change Data Capture for Opportunities is enabled.

Remote site settings have the api domain whitelisted.

The trigger is active.

What could be causing change events to fail to trigger?

1
  • I don't have an answer for you because we're running into the same issue, but sans any change in API access (we're using this internally in our apex code). We seem to have a sporadic issue caused by either the OpportunityChangeEvent not publishing at all, or else not firing the trigger as its supposed to. Did you figure anything out for your particular issue?
    – smohyee
    Mar 29, 2022 at 17:45

0

You must log in to answer this question.

Browse other questions tagged .