Chatter REST API rolls back a transaction used in ContentDownloadHandlerFactory.getContentDownloadHandler() if isDownloadAllowed is false
Last updated 2017-09-08 ·Reference W-4078358 ·Reported By 1 users
Summary
A transaction which has been used in File download customization code gets rolled back if downloading a content of a file using Chatter REST API, when isDownloadAllowed is set to false and redirectUrl is specified.
So, even if Future methods or Queueable jobs are called in a Sfc.ContentDownloadHandlerFactory.getContentDownloadHandler() callback, they are never invoked when the ContentDownloadContext.isDownloadAllowed is set to false in the callback.
Repro
On a fresh org:
1. Create an apex class implmenting Sfc.ContentDownloadHandlerFactory.
public class MyFileDownload implements Sfc.ContentDownloadHandlerFactory {
public Sfc.ContentDownloadHandler getContentDownloadHandler(List<ID> ids, Sfc.ContentDownloadContext c) {
futureMethodCall();
Sfc.ContentDownloadHandler cdh = new Sfc.ContentDownloadHandler();
cdh.isDownloadAllowed = false;
cdh.downloadErrorMessage = 'File is not allowed to download.';
cdh.redirectUrl = '/apex/DownloadError' ;
return cdh;
}
@Future public static void futureMethodCall() {
String msg = 'Future method was invoked';
insert new Account(name = 'acc', description = msg + ' at ' + System.now());
System.debug(msg);
}
}
2. Go to Files table and upload a file.
3. Download the file using Chatter REST API.
3-1. login into workbench
3-2. go to REST Explorer which is in utilities tab
3-3 execute the following GET reqequest:
/services/data/v40.0/connect/files/<file_id>/content
You'll get a response with the status code 302. However, the future method is not invoked. You won't be able to see an Account record whose description field contains the "Future method was invoked" string.
Workaround
NA
Reported By (1)
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.