I am trying to log all the exception in a Debug_Log__c object and send a mail through workflow (written on Debug_Log__c) using platform events.

When I am using the platform event trigger to insert the records in Debug_Log__c object then the workflow is not getting executed.

Below is my code:

public class ResponseHandler extends API.UnTypedResponseHandler{

    protected override Object handleError(){

        //Checking the response code here
        if (this.hr.getStatusCode() == 400) {

            //Getting the record type
            RecordType rt = [SELECT Id, DeveloperName FROM RecordType WHERE SobjectType='Debug_Log__c' AND DeveloperName='sync'];

            //Publishing the event
            EventBus.publish( new Log__e( Log_Type__c = rt.Id, Data__c = 'Request ==> '+this.req+ ' ----- Response ==> '+this.hr));

            //Throwing exception here
            throw Lib_AuraExceptionFactory.create(Lib_AuraExceptionFactory.Cause.callout, 'There was some error syncing the record. The team was informed and they will look into it.');

        } else {
            // go with parent's error handling
            return super.handleError();

Here is the trigger code :

trigger DebugLogGenerator on Log__e (after insert) {

    RecordType rt = [Select Id from RecordType where SObjectType = 'Debug_Log__c' and DeveloperName like 'logs'];

    Debug_Log__c[] recordings = new Debug_Log__c[]{};
    for (Log__e le : Trigger.new){
            new Debug_Log__c(
                Data__c = le.Data__c,
                RecordTypeId = le.Log_Type__c == null ? rt.Id : le.Log_Type__c
    insert recordings;

The same thing which I am doing without a platform event then I am getting the emails through the workflow.

Here is my email alret configuration.

enter image description here

  • 3
    What is the email alert's configuration? Per Doug Ayers' answer here, you'll have to use a default workflow user or Org-Wide Email Address. – David Reed Jul 4 '19 at 13:12
  • N.B. The value of rt.Id can be obtained using describe methods and does not require a soql call – cropredy Jul 4 '19 at 18:30
  • @cropredy thanks, I will make that change. – Tarique Shamim Jul 5 '19 at 5:27
  • @DavidReed I have added the email alert's detail here. – Tarique Shamim Jul 5 '19 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.