> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/maintenance-and-troubleshooting/legacy-workflows/s-doc-jobs-legacy/platform-event-testing.md).

# 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

{% stepper %}
{% step %}

#### Create Platform Event

1. Navigate to Setup > Platform Events
2. Create a platform event named:

```
SDJobCreate__e 
```

3. Add the following fields:

```
objectid__c
objectapi__c
doclist__c
start__c
```

{% endstep %}

{% step %}

#### 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!');
}
```

{% endstep %}

{% step %}

#### Create custom permission set

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

```
SDTemplateController
```

{% endstep %}

{% step %}

#### 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
);
```

{% endstep %}

{% step %}

#### 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);
```

{% endstep %}
{% endstepper %}

{% hint style="info" %}

* 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).
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.sdocs.com/sdocs/maintenance-and-troubleshooting/legacy-workflows/s-doc-jobs-legacy/platform-event-testing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
