function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
garybgaryb 

ContentVersion trigger and future method

Hi all,

 

I have the following code:

 

trigger ContentVersion on ContentVersion (after insert) {
  HelperClass.doStuff(Trigger.newMap.keySet());
}

public class HelperClass {
  @future
  public static void doStuff(Set<ID> recordIDs) {
    System.debug('recordIDs : + ' recordIDs);
    List<ContentVersion> content = [select ID from ContentVersion where ID in :recordIDs];
    System.debug('content : ' + content);
  }

}

 

A trigger that calls a future method, passes in the IDs of the record in the operation, and then retrieves those records from the database. Here's what happens:

 

The first debug statement shows that the recordIDs variable has a value

The second debug statement shows that the content is NOT retrieved - the list is empty.

 

Has anyone else seen this? Am I doing something wrong?

garybgaryb

I this this may be a problem with the Content servlet. I adapted the above test for another object in our system and it behaves as expected.

 

I kind of fell into a temporary workaround. I have a validation rule on Content in my org. This validation rule seems to cause the trigger to fire again - why, I don't know, I wouldn't expect it to - and I put the call to the future method in the update trigger instead.

 

I'm going to raise a case about this.

 

EDIT: Case raised, case number 07591921

garybgaryb

According to support, this is scheduled for a fix on 16th August. Yay!