Apex
Platform Events

Platform Events Apex Handler (Object Type)

considering you've already gone through events docid\ rknln6uow5ow7m1aji6xq 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 docid\ ejrg2isyetemkfncftw8p 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 trigger cloudfilesobjecttrigger on cldfs cloudfilesevent c (after insert) { cloudfileseventtriggerhandler execute(); } trigger handler example public with sharing class cloudfileseventtriggerhandler { public static void execute() { list\<id> recordids = new list\<id>(); for(cldfs cloudfilesevent c obj (list\<cldfs cloudfilesevent c>)trigger new){ recordids add(obj id); } processcloudfilesevents(recordids); } @future(callout=true) public static void processcloudfilesevents(list\<id> recordids) { list\<cldfs cloudfilesevent c> records = \[select id, name, cldfs data c, cldfs object type c, cldfs request id c, cldfs type c, createddate from cldfs cloudfilesevent c where id in \ recordids]; if (records size() == 0) return; //output from geteventdetails list\<cldfs event> returnedevents = new list\<cldfs event>(); //inputs for geteventdetails list\<cldfs geteventdetails flowinput> geteventdetailinputs = new list\<cldfs geteventdetails flowinput>(); //input mapping for geteventdetails for(cldfs cloudfilesevent c record records){ cldfs geteventdetails flowinput singleinput = new cldfs geteventdetails flowinput(); singleinput eventcustomobj = record; geteventdetailinputs add(singleinput); } //get the event details returnedevents = cldfs geteventdetails geteventdetails(geteventdetailinputs); //process the returned events for(cldfs event e returnedevents){ if(e type == 'document processed'){ system debug('context ==> '+e documentprocessed context); system debug('processed document id ==> '+e documentprocessed processeddocumentid); system debug('processed file details ==> '+e documentprocessed file); } } } } apex types for different platform event types line #35 in the example above displays outputs from the documentprocessed docid\ cbqw1iswhv8m ia49ryw 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 file uploaded fileupload docid\ rfrm0ccefnamauhq fj6x file replaced filereplace docid\ hmo1wqywiwkrvyegg1hbm salesforce file attached salesforcefilesattached docid\ paouzfslqyfj1r2cpal6a salesforce file copied salesforcefilecopied docid\ mck 6dm yjpvb3ku dzbj folder created foldercreated docid\ a3 5ipjrcz2hyrozufkvs resource updated resourceupdated docid\ taj9r2evot2fyqtt9viiy content version created contentversioncreated docid\ dactalz0owhdo4hgdza4m content version created batch contentversioncreatedbatch docid\ wput3qqi82o5iuxv hegn file received filereceived docid\ fbfquz7bvioclhlke vjg resource attached resourceattached docid\ sxyta6nleryqqykb60pob document generated documentgenerated docid\ syr eisyvmxipl 2rozje resource cloned resourcecloned docid\ qfvxwwbn8bu71vaxihorr file viewed fileviewed docid 7vdtenfvihudbxovlaxlk document processed documentprocessed docid\ cbqw1iswhv8m ia49ryw document split documentsplit docid\ n8qb7lhs9tpldgpju jiz resource deleted resourcedeleted docid\ g0m1wfdgbj7jgbxarytqv error event errorevent docid omxqz0brj2bv7twjulvh