0

I have a ContentDistributionTrigger trigger after insert & update which when fired has a null value for ContentDownloadUrl.

The ContentDistribution is created in a ContentDocumentLinkTrigger as such:

ContentDistribution cd = new ContentDistribution();
cd.Name = (String)link.LinkedEntityId + ' logo' ;
cd.ContentVersionId = // my id
cd.RelatedRecordId = link.LinkedEntityId;
cd.PreferencesAllowOriginalDownload = true;
cd.PreferencesPasswordRequired = false;
insert cd;

Then in my ContentDistributionTrigger:

trigger ContentDistributionTrigger on ContentDistribution ( after insert, after update ) {

    for (ContentDistribution cd : Trigger.new) {
        System.debug(cd.ContentDownloadUrl);
    }
}

debugs as "null"

Is the ContentDownloadUrl generated after the after insert trigger fires? If so, why don't I catch it in the "after update" run of this trigger?

Thank you,

2
  • 1
    Having the exact same problem. Did you ever find a solution? Commented Aug 12, 2022 at 14:59
  • are you running at V40+ ?
    – cropredy
    Commented Feb 7, 2023 at 20:09

1 Answer 1

0

You need to requery the object based on the trigger context with the fields you want in order to get their values.

List<ContentDistribution> contextList = [ select id, DistributionPublicUrl, ContentDownloadUrl, ContentDocumentId from ContentDistribution where id in :Trigger.new ];

And now you can work with contextList instead of Trigger.new.

3
  • 1
    why is this an answer? the field ContentDownloadUrl is in the trigger context. Your answer normally applies to fetching lookup objects. Have you observed for this object in particular that a SOQL query on the triggered records makes the fields available?
    – cropredy
    Commented Feb 7, 2023 at 20:06
  • Yes I have. I had the same issue as the OP where the value was null in the trigger.new context but present when I requeried.
    – bsbab
    Commented Feb 9, 2023 at 0:35
  • fascinating - I'm stunned
    – cropredy
    Commented Feb 9, 2023 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .