10

A bit of background: I have a client that I built a custom model library for, and in this page they can select a group of models and email them (say instructions to the next gig or notify them of upcoming events etc). The client wants to be able to share content in these emails, and at first we tried attaching the content (all of her doc's are in in crm content) to the emails. The page would display a list of content that she could choose from to attach. This causes a few problems:

  • Since the fileType returned was not the type the email api was looking for it had to be converted so a custom setting is used...(my previous question about this) this has to be kept up to date manually and isn't an ideal solution. If the right extension isn't found the file defaults to a standard HTML doc and its up to the user to know what extension to save the file with.. and assuming that the end recipient isn't a computer savvy person..this would not be a good user experience
  • There is a 10MB limit on emails and the attachments, so only 2 maybe 3 attachments could be included per email. Unfortunately she wanted to include much more than 2 or 3 attachments.
  • Since you cant search within the tag field on ContentVersion via SOQL, a trigger would be needed to replicate the tag field into a new one that can be searched, however, 1 of 3 ways tags are added to content doesn't always fire a dml update so the trigger isn't fired, and thus the field isn't always up-to-date. So the content showing in the 'send email' page could get lengthy/unusable as content is added.

Whats needed is a way to send content to non-sfdc users that they can access/downloaded easily via a link (I think this is the best solution, but am open for suggestions). I would go the rout of making them all chatter users, but this is not an ideal solution since we want to avoid them having to log-in to anything/get setup etc. Also I would do a sites page, but again, this isn't the best solution for security reasons. Since it seems that going the file attachment rout isn't going work well with the use-cases, is there a way (via apex) to expose the content(or files) via link to non users?

When looking into this, it seemed that there are ways to do it via the UI but not the API, at least with CRM Content, and potentially chatter 'files'. Questions:

  • In the UI for files I see that I can generate a link that anyone (even non-org users) can click and see, but not sure how to achieve that via the API

link that is shared

  • In CRM Content, there is the ability to group content and share it via a Content Pack, but I am not seeing a way to allow someone to create Content Packs via the API so it can be shared. Then once it is grouped, can it be shared to non-org users?
  • Based off this Question could I use the same approach in an email? Does it work with Content/Files?

Any help or direction for this would be awesome!

5

According to this post, the answer to your question about using content packs would be "no".

On the IdeaExchange you'll find a submission titled Allow Content Deliveries to be programmatically generated via Apex which has some related links on it you may also want to look at. Regardless, I believe this "idea" covers the gist of your question.

It seems to me that you might want to go and vote for this idea.

With a bit more effort, I believe I've found something in another post that you might be able to utilize the techniques from for getting a download link in it to accomplish your task. There are references to a blog post titled Salesforce: How to make a Document public? and some other useful discussion.

Based on the above referenced post, I'd say the answer to your final question is "yes". Implementation will be a matter of how you design your trigger and email template(s).

For future reference, you might find FindSF Info to be a very helpful search engine.

12

The idea thread mentioned by @crmprogdev is now realized.

As of winter 15 there is now programmatic access to content deliveries.

ContentDistribution cd = new ContentDistribution();
cd.name = 'test';
cd.ContentVersionId = '12312132abad';
cd.PreferencesAllowOriginalDownload = false;
cd.PreferencesAllowPDFDownload = false;
cd.PreferencesAllowViewInBrowser = true;
insert cd;

cd = [SELECT DistributionPublicUrl FROM ContentDistribution WHERE ID = :cd.Id];
System.debug(cd.DistributionPublicUrl);

Basically you can do anything the standard Content Delivery UI will allow you to do.

enter image description here

There doesn't yet seem to be any official documentation on the object, but you can explore it using workbench. Just make sure your API version is set to 32

screenshot ContentDistribution Object in workbench

  • 2
    This should be changed to be the accepted answer. This is now possible. In the current Spring '18 version, there is also a field called ContentDownloadUrl, which allows you to download the content directly, without having to go through the preview page first. – tlfu Mar 15 '18 at 12:39
0

The below solution is working for me. In short, you can insert a new ContentDistribution object if you have your ContentVersionId, just plug that in at construction, Name is the only other required field, but you can configure multiple options (allow download, etc) as provided here: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdistribution.htm

After inserting, the DistributionPublicUrl is generated automatically for you. Should look something like this:

ContentDistribution cd = new ContentDistribution();
cd.Name = cv.Title;
cd.ContentVersionId = cv.Id;
insert cd;
System.debug(cd);
List<ContentDistribution> cdList = [SELECT Id, DistributionPublicUrl 
                                    FROM ContentDistribution 
                                    WHERE ContentVersionId =: cv.Id 
                                    AND Name =: cv.Title];
System.debug(cdList[0].DistributionPublicUrl);

This also does not seem to get overwritten if a new Public URL is created/deleted/etc...which may change in the future, so heads up. Shout with any questions.

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.