Apex
Platform Events

Platform Events Apex Handler (Object Type)

Considering you've already gone through Platform Events section of the documentation, this article will walk you through how to write a trigger on the cldfs__CloudFilesEvent__c object and handle custom logic based on the event type.

If you've set the setting to Platform Events, go through this article - Platform Events



Document image


Basic Example:

Note: Salesforce does not allow callouts from the trigger context. Therefore, please make the callout in an asynchronous context. In the example below, we used a future method to make the callout. Salesforce Article Link

Trigger Example:

Apex


Trigger Handler Example:

Apex


Apex Types for different platform event types:

Line #35 in the example above displays outputs from the DocumentProcessed event type(i.e. type number 14 in the list below). Depending on your use case, Here are the avilable platform event types and their custom Apex types that you may use to access relevant information:

  1. file-uploaded - FileUpload
  2. file-replaced - FileReplace
  3. salesforce-file-attached - SalesforceFilesAttached
  4. salesforce-file-copied - SalesforceFileCopied
  5. folder-created - FolderCreated
  6. resource-updated - ResourceUpdated
  7. content-version-created - ContentVersionCreated
  8. content-version-created-batch - ContentVersionCreatedBatch
  9. file-received - FileReceived
  10. resource-attached - ResourceAttached
  11. document-generated - DocumentGenerated
  12. resource-cloned - ResourceCloned
  13. file-viewed - FileViewed
  14. document-processed - DocumentProcessed
  15. document-split - DocumentSplit
  16. resource-deleted - ResourceDeleted
  17. error-event - ErrorEvent