0

We are trying to switch from Notes and Attachments to Salesforce Files but have run into an issue with file attachments being loaded from a web form.

Currently a person can populate the form fields, attach a file and click the submit button on the web page - this in turn creates (2) custom objects and attaches the file to one of the custom objects under the Notes and Attachments related list - this has been working for more than a year.

I have completed all of the necessary tasks in our Salesforce Sandbox to switch to files and I have a test web site connected to the sandbox org to test the form submissions. Everything comes through as described above BUT there is no "file" in the "Files" related list on the new record. I am assuming I need to change the coeding on the website but neither my web site developer or I have a clue as to what needs to change.

See below the coding which currently handles the file attachment from the web site form any help or suggestions would be greatly appreciated.

    // CV attachment object
    $jobAttachment = null;
    $candidateAttachment = null;
    if ($cv['tmp_name']) {
        $jobAttachment = new stdClass();
        $candidateAttachment = new stdClass();

        $jobAttachment->Name = $candidateAttachment->Name = $cv['name'];
        $jobAttachment->ContentType = $candidateAttachment->ContentType = $cv['type'];
        $fileContent = base64_encode(file_get_contents($cv['tmp_name']));
        $jobAttachment->Body = $candidateAttachment->Body = $fileContent;
    }
1
  • You should first create the content version, then the ContentDocumentLink related to this ContentVersion. Mar 14, 2019 at 12:28

1 Answer 1

1

See here for the API reference on ContentVersion which is what new Files get uploaded to:

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/api/sforce_api_objects_contentversion.htm

Note that these have a many-to-many relationship with objects through ContentDocumentLink as Retreever noted. However on first insert of a ContentVersion you can specify one first object to attach it to in the field FirstPublishLocationId. The insert will then also auto-generate a ContentDocument and link it to the first publish location with a ContentDocumentLink.

See the ERD here for more info: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_content.htm And this one to understand where ContentDocumentLink fits in (just substitute ContentDocument for ContentNote): https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_contentnote.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .