I have to write an API Query to get all the opportunities, Quotes and its associated Attachments to another team that are outside salesforce in my office. Will they be able to download the Attachment-(queried with the help of API)?

  • 2
    Am I correct in assuming that this "other team" of yours does not have the ability to log into Salesforce? – Derek F Nov 29 '16 at 18:21
  • Yes. They do not have access to Salesforce. – Rohith Raj Nov 29 '16 at 18:22
  • Also, can you explain a bit more about how you are running this query? The way you worded things makes me think that you are working outside of Salesforce using a program/script in a language like Java, C#, or PHP and communicating with Salesforce using either the REST or SOAP API. – Derek F Nov 29 '16 at 18:29
  • No. It is my manager who is writing the query. I am new to Salesforce API and code. I was asked to research whether the team that are outside Salesforce can download anything that is under Notes & Attachments if they have access to it. I have searched the internet for the past 5 hours and couldn't find anything on it. So I decided to make this post. Sorry if I wasted your time. – Rohith Raj Nov 29 '16 at 18:45
  • You can set up a force.com site to deliver content without the user being logged in, I used one to deliver a static resource json file for a project a while back. However, I'd be cautious about anything that allowed salesforce content to be accessed without being logged in- it could be viewed as a violation of the terms of service. – battery.cord Nov 29 '16 at 18:59

From the additional information covered in the comments on the question:

  • The "other team" does not have access to Salesforce (no licenses)

I'm assuming that the query will be performed by a program/script outside of Salesforce, using the REST API.

I'm also assuming that you (or your manager) already know how to use the REST API (including authenticating with Salesforce via one of the OAuth flows) to run a query against data stored in Salesforce.

With that information in hand, I can say that the answer to your question is no. You cannot download an attachment that you've retrieved from a query ...at least not directly.

Technically speaking, by getting a response from your query, you have downloaded the data from Salesforce. However, the result of your query will be a string in JSON format, and the actual data of your attachment (stored in the Body field) is encoded as Base64. Both of these present obstacles in actually delivering the attachments (that is, you won't be able to simply send the data to a browser and have the 'save file' dialog box pop up).

For single attachments, you could look at using sObject Blob Retrieve. You should be able to extract the attachment Ids from your query. From there, you would run an additional API call for each of the attachment Ids. This method isn't exactly friendly for more than a couple of attachments.

With additional processing, you could feasibly take the base64 encoded attachment bodies and package them in a zip file that you would present to the user for download.

You also may be able to use the base64 encoded values as a data-uri, which you may be able to present on a more user-friendly web page for downloading. I haven't done this myself, and goes beyond the scope of this site, but this question on StackOverflow may get you started.

| improve this answer | |
  • About this statement-(I'm assuming that the query will be performed by a program/script outside of Salesforce, using the REST API.) If we were to find a way to use Salesforce API, would the answer to my question still be no? – Rohith Raj Nov 29 '16 at 20:23
  • 1
    The REST API is analagous to the 'Salesforce API' that you're talking about. REST is simply one way of exposing the functionality of Salesforce's various APIs (the other main one being SOAP). – Derek F Nov 29 '16 at 20:29

As long as the attachments are not marked private and they have view access to the record itself, then they would have access to the attachments.

By Attachment I am referring to anything that is in the Notes & Attachments Related List - not files.

| improve this answer | |
  • 1
    I could be mistaken, but I think that Rohith Raj is asking about if people without Salesforce licenses can download something from within Salesforce. – Derek F Nov 29 '16 at 18:17
  • If they have access to it, they will be able to download it. Is that correct? – Rohith Raj Nov 29 '16 at 18:18
  • If they have access to the record, they will have view/download access to any attachments on the record. – citizen conn Nov 29 '16 at 18:20
  • @DerekF yeah I assumed the API users would be authenticated - I guess my answer makes it clear enough that they have to have read access to the record in order to see any attachments on it. – citizen conn Nov 29 '16 at 18:28

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.