I need to upload pdfs to some custom objects in SF through the API. Right now I am using restforce in ruby to interact with the API, but I can't seem to figure out how to (neither in restforce nor in the API in general) attach them to the Files or Attachments of the relevant object. It seems like all of the code I see is just to upload to a "Document". Can someone point me in the right direction?



You can use attachment object to insert into attachment

client.create('Attachment', ParentId: 'RecordIdOfparent',
                      Description: 'Document test',
                      Name: 'My image',
                      Body: Restforce::UploadIO.new(File.expand_path('image.jpg', __FILE__), 'image/jpeg')

Note that "RecordIdOfparent" is the parentId of salesforce record for which you want to insert the attachment .

Attachments are getting retired and salesforce files are the right object to target .

You can insert data into ContentVersion record

                      pathOnClient: '/document.txt',
                      title: 'My image',
                      versionData: Restforce::UploadIO.new(File.expand_path('image.jpg', __FILE__), 'image/jpeg')

Use LinkedEntityId as the salesforce recordId of which you want files to be associated with .

  • Thanks! And this works for restforce?
    – skaz
    Jul 11 '17 at 14:23
  • 'LinkedEntityID' doesn't exist...
    – skaz
    Jul 11 '17 at 14:27
  • Omit the LinkedEntityId . You can use ContentDocument Object to link the File to the parentId once you have the ContentVersionID Jul 11 '17 at 14:41

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.