4

I have a Site, where external, unauthenticated users can access some of the files we store in Salesforce. To achieve this, I use Content Distribution records, to obtain the public URLs for these files. The Visualforce page displayed in the Site has a controller, which queries related ContentDistribution records and displays the links. This was working fine up until a few days ago (possibly up until the Winter'19 release).

Currently when external users try to access the files, the controller throws an error: sObject type 'ContentDistribution' is not supported

As a workaround I moved querying ContentDistribution to a without sharing class and use a Custom wrapper class to hold the name and URL of the file, but this doesn't seem like a good solution in the long term.

Is there any new feature or critical update, that I missed, that takes away access to ContentDistribution from public Site users? And if so, is there any better way to allow unauthenticated users see/download files from a Salesforce org?

I know about the "share via link" option on files - but I haven't found any resources on how to use it programmatically (both to create the public link and to query it).

4
  • if you can log a case with support you might be able to get some traction, just make sure to call it out as a "Regression" and be very clear the same code worked prior to Winter '19. With a bit of luck you might get through to someone knowledgeable who can steer you around whatever issue has come up, and or tell you they intentionally broke your stuff and it's never coming back (hopefully not) Nov 7 '18 at 6:24
  • ps there was also a recent critical update which recent some permission for guest user profiles, you might double check the profile settings still grant access to that document Nov 7 '18 at 6:25
  • Thanks. I have logged a case as well. Will update here if I find out anything. Nov 7 '18 at 10:41
  • Unfortunately, Support's answer is that Content Delivery records were never meant to be accessed by Guest users (so I guess in the past this was working unintentionally). They have pointed me to the critical update you mentioned: releasenotes.docs.salesforce.com/en-us/winter19/release-notes/… and also this Idea: success.salesforce.com/ideaView?id=08730000000cH2vAAE. "Sigh!" :( I'll leave the question open in case someone will have a good idea on how to deal with this in the post-Winter'19 world Nov 12 '18 at 8:45
1

The answer is to use a without sharing class that does access control and only delivers the data the current guest user is allowed to access. You should not be granting declarative access to objects to guest users as there is no way to distinguish them. In your controller, you can distinguish them.

In general when you have guest users your controllers will need to be without sharing. Of course this requires you to be very careful in implementing your own procedural access control logic, but that's better than granting blanket access to anonymous internet users to read your organization's data. For example if you have a without sharing controller you can do things like use secure tokens in cookies, rely on a third party service to identify the user, and require captchas. A combination of these techniques can allow you to add your own access control logic when dealing with guest users and only serve data to them which they are allowed to see. But if you mark an object as accessible to the guest user, then they can use standard controllers to access that object at any time, and your code will not be able to deny them access.

For additional examples of using the above patterns in without sharing controllers to give controlled access to guest users, look at this blog post: https://www.learnexperiencecloud.com/s/article/Guest-User-Record-Access-Development-Best-Practices

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.