1

I have created a Platform Event with some fields, and a trigger for it. I have also created a VF Page and subscribed to that event.

From the developer console, I publish an event in this manner.

List<Stripe_Authorize__e> publishEvents = new List<Stripe_Authorize__e>();
Stripe_Authorize__e eve = new Stripe_Authorize__e();

eve.SessionID__c = '123';
eve.PaymentIntentID__c = '1234'; 
eve.Transaction_Helper_ID__c = '66';
eve.Post_Authorization_Status__c = '1' ;
publishEvents.add(eve);    

// Call method to publish event
List<Database.SaveResult>  results = EventBus.publish(publishEvents);
// Inspect publishing result for each event
for (Database.SaveResult sr : results) {
    if (sr.isSuccess()) {
        System.debug('Successfully published event.');
        // Get asynchronous operation ID.
        System.debug(EventBus.getOperationId(sr));

        // The getOperationID call above is equivalent to the err.getMessage() call
       for(Database.Error err : sr.getErrors()) {
       System.debug('Error returned: ' +
                    err.getStatusCode() +
                    ' - ' +
                    err.getMessage());
        }

    } else {
        for(Database.Error err : sr.getErrors()) {
            System.debug('Error returned: ' +
                         err.getStatusCode() +
                         ' - ' +
                         err.getMessage());
        }
    }       
}

So far so good, I'm getting in my VF page the message BUT The trigger of that event never fires. I'm getting these messages from the debug log

USER_DEBUG|[17]|DEBUG|Successfully published event.

USER_DEBUG|[19]|DEBUG|6fe2cd26-1161-42a3-b229-886d18cabaaa

VARIABLE_SCOPE_BEGIN|[22]|err|Database.Error|true|false 15:07:29.1

(14367228)|VARIABLE_ASSIGNMENT|[22]|err|"Error [statusCode=OPERATION_ENQUEUED, code=[xmlrpc=-1, statusCode=OPERATION_ENQUEUED, exceptionCode=null, scope=PublicApi, http=202], message=6fe2cd26-1161-42a3-b229-886d18cabaaa, fields=null]"|0x697034ba

I can't understand what this message means, and if that has to do with the non-firing trigger.

I have the debug "Automated Process" To be active and it's not showing I also tried publishing the event from "workbench" through Rest Post the same thing happens, I receive the event on the VF Page but Trigger not firing.

(just to mention, when I did start this few days ago, I did manage to notice the "Automated Process" but not anymore.

Maybe a limit problem? I hope someone can help with this.

here is also the trigger :

trigger StripeAuthorize on Stripe_Authorize__e (after insert) {

    system.debug('Stripe Authorise Trigger - Platform Event');
    List<Transaction_Helper__c> thoList = new List<Transaction_Helper__c>();

    for (Stripe_Authorize__e event: trigger.new)
    {
        Transaction_Helper__c tho = new Transaction_Helper__c(id = event.Transaction_Helper_ID__c);
        tho.Payment_Intent__c = event.PaymentIntentID__c;
        thoList.add(tho);
    }
    insert thoList ;
}
2
  • can you post code of a trigger as well? Sep 1, 2019 at 15:10
  • @Oleksandr Berehovskyi added the trigger also in the message thx Sep 1, 2019 at 15:41

1 Answer 1

1

I suspect something like the following is occurring.

Firstly, the Database.SaveResult isSuccess() method indicates that the event was successfully published. But then you attempt to iterate the Database.Error records via sr.getErrors(). That is resulting in the VARIABLE_ASSIGNMENT error, as there aren't any errors to iterate. I'm assuming this is resulting in an exception that causes the transaction to rollback.

The second assumption here is that the Platform Event has the Publish Behavior set to "Publish After Commit".

enter image description here

With the transaction rolling back the event would never be published to the Apex trigger.

What this scenario doesn't explain is why the Platform Event is reaching the Visualforce page.

1
  • There are a number of assumptions in this answer. E.g. if your Publish Behavior is set to Publish Immediately or there isn't an exception occurring when checking the errors in the success case it wouldn't really hold up. Sep 1, 2019 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .