Skip to main content
corrected variable name
Source Link
Guy Clairbois
  • 10.8k
  • 32
  • 54

I ran across this the other day while converting a process that was using attachments to use the new Files feature. What fixed it for me was setting the FirstPublishedLocationId to the record.

So in your example

public ID createFileFromUploadedFile(Id parentId) {
        ID docID = null;
        ContentVersion cv = new ContentVersion();
        cv.versionData =  file.Body;
        cv.title = file.FileName;
        cv.pathOnClient = file.FileName;
     ** cv.FirstPublishedLocationIdFirstPublishLocationId = parentId **
    insert cv;

I ran across this the other day while converting a process that was using attachments to use the new Files feature. What fixed it for me was setting the FirstPublishedLocationId to the record.

So in your example

public ID createFileFromUploadedFile(Id parentId) {
        ID docID = null;
        ContentVersion cv = new ContentVersion();
        cv.versionData =  file.Body;
        cv.title = file.FileName;
        cv.pathOnClient = file.FileName;
     ** cv.FirstPublishedLocationId = parentId **
    insert cv;

I ran across this the other day while converting a process that was using attachments to use the new Files feature. What fixed it for me was setting the FirstPublishedLocationId to the record.

So in your example

public ID createFileFromUploadedFile(Id parentId) {
        ID docID = null;
        ContentVersion cv = new ContentVersion();
        cv.versionData =  file.Body;
        cv.title = file.FileName;
        cv.pathOnClient = file.FileName;
     ** cv.FirstPublishLocationId = parentId **
    insert cv;
Source Link
JRiffe
  • 1.7k
  • 12
  • 21

I ran across this the other day while converting a process that was using attachments to use the new Files feature. What fixed it for me was setting the FirstPublishedLocationId to the record.

So in your example

public ID createFileFromUploadedFile(Id parentId) {
        ID docID = null;
        ContentVersion cv = new ContentVersion();
        cv.versionData =  file.Body;
        cv.title = file.FileName;
        cv.pathOnClient = file.FileName;
     ** cv.FirstPublishedLocationId = parentId **
    insert cv;