1

I'm trying to insert a record to ContentDistribution object using the following:

Here is the doc says: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdistribution.htm?search_text=ContentDistribution

ExpiryDate Type: dateTime

ContentDistribution cdl = new ContentDistribution();
cdl.ContentVersionId = 'id goes here...';
cdl.Name = 'PublicShare';
cdl.ExpiryDate = Datetime.now().addDays(1);
insert cdl;

If I don't provide the ExpiryDate then I was able to insert the record, I'm not sure what ExpiryDate is expecting.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You must specify the expiry option if an expiry date is set.: [ExpiryDate]

2
  • I have seen a similar issue in past. Can you try setting ContentDistribution.PreferencesExpires = true; and confirm if that fixes the issue Feb 17, 2021 at 6:17
  • 1
    yep the error is very confusing, after I try the PreferencesExpires = true then I was able to insert the record, please post that as answer.
    – Nick
    Feb 17, 2021 at 6:25

1 Answer 1

0

You need to set PreferencesExpires as true to fix the error

ContentDistribution cdl = new ContentDistribution();
cdl.ContentVersionId = '0696F00000U3VzSQAV';
cdl.Name = 'PublicShare';
cdl.PreferencesExpires = true; 
cdl.ExpiryDate = Datetime.now().addDays(1);
insert cdl;

As per the documentation,

PreferencesExpires: When true, access to the shared document expires on the date that’s specified by ExpiryDate.

You must log in to answer this question.

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