# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
