I have followed this to create a content version from vf page using sforce ajax and it is working fine.
To link the uploaded content to one of my custom object I added the below code;
var result1 = sforce.connection.retrieve("id,ContentDocumentId", "ContentVersion", [results[0].id]);
console.log('1---'+result1[0].ContentDocumentId);
var contentDocumentLink = new sforce.SObject('ContentDocumentLink');
contentDocumentLink.ContentDocumentId = result1[0].ContentDocumentId;
contentDocumentLink.LinkedEntityId ='a0F2800000D7cXF';
contentDocumentLink.ShareType = 'I';
results = sforce.connection.create([contentDocumentLink]);
console.log('2---'+results);
But every time it throws exception.
Log:
2—{errors:{fields:'LinkedEntityId', message:'You cannot create a link for this type of entity through the api: Linked Entity ID', statusCode:'FIELD_INTEGRITY_EXCEPTION', }, id:null, success:'false', }
Is there a way to create ContentDocumentLink from javascript?
Best Answer
Please find my below code: -
The code is running perfectly. Just check below things : - 1. version of API 2. then check share Type. 3. After that the permission on object record.