You need to sign in to do that
Don't have an account?
Abhisree
Can't create new ContentDocumentLink
We have a custom inbound email service that attaches inbound emails as attachments to certain objects. I'm trying to change the code to create a file instead but get an error when trying to create a new ContentDocumentLink to attach the document to the object. Thanks in Advance.
Error: Invalid type:ContentDocumentLink
Error: DML requires SObject or SObject List Type: ContentDocumentLink
I think my content settings are correct.
Code snippet for reference:
else
{
ContentVersion conVer = new ContentVersion();
Long sz;
if(email.subject.length()>80)
{
conVer.Title= email.subject.substring(0,80);
}
else
{
conVer.Title= email.subject;
}
conVer.PathOnClient =conVer.Title+'.pdf';
if(email.plainTextBody == null)
{
conVer.VersionData = blob.valueof(email.htmlBody);
sz = email.htmlBody.length();
}
else
{
conVer.VersionData = blob.valueof(email.plainTextBody);
sz = email.plainTextBody.length();
}
insert conVer;
Id condId=conVer.ContentDocumentId;
ContentDocumentLink cdl = New ContentDocumentLink(LinkedEntityId = book.id, ContentDocumentId = condId, shareType = 'I');
insert cdl;
Error: Invalid type:ContentDocumentLink
Error: DML requires SObject or SObject List Type: ContentDocumentLink
I think my content settings are correct.
Code snippet for reference:
else
{
ContentVersion conVer = new ContentVersion();
Long sz;
if(email.subject.length()>80)
{
conVer.Title= email.subject.substring(0,80);
}
else
{
conVer.Title= email.subject;
}
conVer.PathOnClient =conVer.Title+'.pdf';
if(email.plainTextBody == null)
{
conVer.VersionData = blob.valueof(email.htmlBody);
sz = email.htmlBody.length();
}
else
{
conVer.VersionData = blob.valueof(email.plainTextBody);
sz = email.plainTextBody.length();
}
insert conVer;
Id condId=conVer.ContentDocumentId;
ContentDocumentLink cdl = New ContentDocumentLink(LinkedEntityId = book.id, ContentDocumentId = condId, shareType = 'I');
insert cdl;
I think you'll also need to create a ContentDocument: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocument.htm
That's where you'd load the attachment
Or to make this process even easier, just use the Attachment object, then no need for multiple objects like you're using. There are some downfalls to using just Attachment so I can see why you would want to use the Content Docs.
This is how I attach a document to a custom object: