0

I am in one of the requirements where I need to set IsArchived = true when user uploading any files using Upload files option.

I thought apex trigger will work here but it doesn't

trigger setFileArchived on ContentDocument (before insert) {
    for(ContentDocument ct : trigger.new){
        system.debug('---->'+ct.isArchived);
        ct.isArchived = true;
    }
}

Can anyone help me to find a way?

0

Having a look at the workbench for the object 'ContentDocument' we can see that the field IsArchived is updateable

https://workbench.developerforce.com/describe.php

The few things I'd recommend is

  1. Match your case for the field name (you're using isArchived not IsArchived)
  2. Use 'after insert' instead of 'before insert'

However, looking at the related questions, if "How to Create Archived Task" is still up to date

The archiving process occurs automatically on a background task provided by the system (I think every hour or so). You can't actually force the IsArchived flag to be set to true.

  • I did modify the code as per recommendations, but it seems result is as it is. If the archiving process occurs automatically on a background task then do you know how can I make the file as archived when user upload ? any other option / work around. – Nail David Oct 21 at 12:30
  • @NailDavid Out of curiosity, why would you archive files automatically after the customer uploads them? Would it be worth creating your own 'Archived' checkbox that you could edit and filter on? – David Picksley Oct 21 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.