You need to sign in to do that
Don't have an account?
REVNA
ContentVersion PDF Type
I am using below code to create a File in Apex and attach it to one of the LEads.
The PDF file type does get attached . But when I preview it / Download it - there are errors.
"Preview not available" OR "Error loading Files".
Any idea what mistake I am doing ?
The PDF file type does get attached . But when I preview it / Download it - there are errors.
"Preview not available" OR "Error loading Files".
Any idea what mistake I am doing ?
Blob yourFiles = Blob.valueOf(‘MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY’); ContentVersion conVer = new ContentVersion(); conVer.ContentLocation = ‘S’; conVer.PathOnClient = ‘test’+’.’+’pdf’; conVer.Title = ‘Sample’; conVer.VersionData = EncodingUtil.base64Decode(s); conVer.origin = ‘H’; insert conVer; Id conDoc = [SELECT FileExtension ,ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId; ContentVersion cv = [SELECT Title, FileExtension, VersionData, ContentDocumentId, ContentLocation, FileType FROM ContentVersion WHERE ContentDocumentId = :conDoc AND IsLatest = true]; //Create ContentDocumentLink ContentDocumentLink cDe = new ContentDocumentLink(); cDe.ContentDocumentId = conDoc; cDe.LinkedEntityId = ‘XXXXXXXXX’; cDe.ShareType = ‘I’; cDe.Visibility = ‘InternalUsers’; insert cDe;
conVer.ContentLocation = 'S';
conVer.PathOnClient = 'test930.pdf';
conVer.Title = 'Proposal1Tuesday10';
conVer.VersionData = Blob.valueOf('Test Content');
conVer.origin = 'H';
insert conVer;
Id conDoc = [SELECT FileExtension ,ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
ContentVersion cv =
[SELECT Title, FileExtension, VersionData, ContentDocumentId,
ContentLocation, FileType
FROM ContentVersion
WHERE ContentDocumentId = :conDoc
AND IsLatest = true];
//Create ContentDocumentLink
ContentDocumentLink cDe = new ContentDocumentLink();
cDe.ContentDocumentId = conDoc;
cDe.LinkedEntityId = '00Q7A000004eSiUUAU';
cDe.ShareType = 'I';
cDe.Visibility = 'InternalUsers';
insert cDe;
Sorry I am using this code. And the PDF that is getting generated does not give me a preview. Nor has anything in it when I download it.
But when I open the pdf on my machine as TXT , it does have the content in it as - "Test Content".