+ Start a Discussion
Jayesh Babu A VJayesh Babu A V 

How to share an attachment using url?

I am new to saleforce and I used the following code to save files to the Attachment object in salesfore:
String base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
Attachment attach = new Attachment();
attach.ParentId = parentId;
attach.Body = EncodingUtil.base64Decode(base64Data);
attach.Name = fileName;
attach.ContentType = contentType;
attach.IsPrivate = false;
insert attach;
Now, I need to generate an url by which the files can be shared outside of the salesforce. After some googling,  I found out that it can be done using ContentDistribution. And I want to generate the url in the apex class itself. I have reffered to many tutorials and no one them worked for me. So, please anyone can provide me with the code or point to a proper tutorial link which expalins the process properly how the sharable url is generated?
 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Jayesh,

I found the developer thread that I believe has a similar implementation issue, can you please have a look at it once:

>> https://success.salesforce.com/answers?id=9063A000000e0ZkQAI

In case if this link and information came in handy can you please choose this as best answer so that it can be used by other in the future.

Regards,
Anutej