For the complete documentation index, see llms.txt. This page is also available as Markdown.

Platform Event Testing

Some clients continue to use SDJobs along with Platform Events. This article will cover steps to quickly test platform events with creating SDJobs if any concerns arise in the future.

Create a Platform Event and Run Execute Anonymous

1

Create Platform Event

  1. Navigate to Setup > Platform Events

  2. Create a platform event named:

SDJobCreate__e 
  1. Add the following fields:

objectid__c
objectapi__c
doclist__c
start__c
2

Create an Apex Trigger

  1. Navigate to Developer Console > File > New > Apex Trigger

  2. Create an apex trigger on SDJobCreate__e

  3. Add the following to the Apex Trigger:

trigger Createsdjob on SDJobCreate__e (after insert) {
    List<SDOC__SDJob__c> sdjobRecords = new List<SDOC__SDJob__c>();
    
    for (SDJobCreate__e eventRecord : Trigger.new) {
        SDOC__SDJob__c sdjob = new SDOC__SDJob__c();
        sdjob.SDOC__Oid__c = eventRecord.objectid__c; 
        sdjob.SDOC__ObjApiName__c = eventRecord.objectapi__c;
        sdjob.SDOC__Doclist__c = eventRecord.doclist__c; 
        sdjob.SDOC__Start__c = eventRecord.start__c;
        sdjob.SDOC__SDCreate3_Parameters__c = '&queryInSystemMode=true&queryWithoutSharing=true';
        sdjobRecords.add(sdjob);
    }


        insert sdjobRecords;
        System.debug('Order tracking records created successfully!');
}
3

Create custom permission set

  1. Create a custom permission set labeled 'Autoproc User' containing the following APEX Class:

SDTemplateController
4

Add the permission set using Execute Anonymous

insert new PermissionSetAssignment(
   AssigneeId = [SELECT Id FROM User WHERE alias = 'autoproc'].Id,
   PermissionSetId = [select id from permissionset where name = 'Autoproc User'].Id
);
5

Publish a Platform Event (Execute Anonymous)

Run the following in Execute Anonymous:

SDJobCreate__e eventrecord = new SDJobCreate__e();
    eventRecord.objectapi__c='Opportunity'; // Object API Name
    eventRecord.objectid__c='006O200000APD2fIAH'; // Object ID
    eventRecord.doclist__c='a06O200000APCzoIAH'; // Template ID
    eventRecord.start__c=true; // Generate document upon insertion of S-Docs Job


EventBus.publish(eventRecord);

System.debug('Published event with ObjectID: ' + eventRecord.objectid__c);
  • The SDJob should be created as the autoproc user.

  • If the user needs to test a specific object/template, the changes can be made in execute anonymous.

  • If the platform event is created successfully but the SDJob is not created, enable debug logs on Automated Process (not a user).

Last updated

Was this helpful?