Skip to main content
Question

Box for Salesforce createFileFromAttachment with ContentDocument

  • May 22, 2025
  • 4 replies
  • 125 views

Forum|alt.badge.img

We created a trigger in Salesforce on the Case object to automatically add any Attachments to Box using the createFileFromAttachment File Operation

 

https://developer.box.com/docs/box-for-salesforce-developer-toolkit#section--createfilefromattachment-

 

Salesforce has changed their attachment process to ContentDocument

Is there a similar boxToolkit method for adding ContentDocuments?

4 replies

Forum|alt.badge.img

Almost a year later - is there any way to move a file from Salesforce's Files to Box similar to the createfilefromattachment?

 

https://developer.box.com/docs/box-for-salesforce-developer-toolkit#section--createfilefromattachment-

 

We switched to Lightning and all files are now being added as Files instead of Attachments and SF is not part of our content strategy.


Forum|alt.badge.img

There is a pretty ugly workaround you can use in Apex. 

 

ContentVersion cv = [SELECT VersionData, Title, FileExtension FROM ContentVersion WHERE ContentDocumentID = YOUR-CONTENT-DOC];

Attachment myAttachment  = new Attachment(Name = cv.Title + '.' + cv.fileExtension, Body = cv.VersionData, ParentID = YOUR-PARENT-ID);


Then you can call the boxtoolkit createFromAttachment, pass in "myAttachment" . No need to actually insert the attachment. 

Not ideal, but if your users are uploading Files instead of attachments, it's a way around. 

 

 


Forum|alt.badge.img

Any other way for ContentDocument file upload with toolkit?


Forum|alt.badge.img

Try this:

ContentVersion cv = [SELECT VersionData, Title, FileExtension FROM ContentVersion WHERE id =: contentVersionId];
BoxFolderfolder = newBoxFolder(api, folderId);
BoxFile.InfofileInfo = folder.uploadFile(cv.VersionData, cv.Title + cv.FileExtension);